100% found this document useful (1 vote)
92 views14 pages

Tries Data Structure

Tries are a data structure that store keys in a prefix tree, allowing for fast lookup, insertion, and retrieval of strings. Tries have three main types - standard tries which store each string as a path from the root, compressed tries which merge nodes with a single child, and suffix tries which store all suffixes of a text. Tries are used in applications like word matching, prefix matching, and as the index for web search engines to store words and associated URLs faster than hashtables.

Uploaded by

keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
92 views14 pages

Tries Data Structure

Tries are a data structure that store keys in a prefix tree, allowing for fast lookup, insertion, and retrieval of strings. Tries have three main types - standard tries which store each string as a path from the root, compressed tries which merge nodes with a single child, and suffix tries which store all suffixes of a text. Tries are used in applications like word matching, prefix matching, and as the index for web search engines to store words and associated URLs faster than hashtables.

Uploaded by

keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

TRIES DATA STRUCTURE

Understand Requirements
Insertion is faster as compared to the Hash
Table
Lookup is much more faster than hash
table implementations
You can store as many keys as much you
want without any reconstruction as like in
Hash Table if size becomes full
There are no collision of different keys in
tries

What is TRIE?
The term trie comes from retrieval. This
term was coined by Edward Fredkin, who
pronounce it tri as in the word retrieval
In computer science, a trie, also called
digital tree and sometimes radix tree or
prefix tree
All the descendants of a node have a
common prefix of the string associated
with that node, and the root is associated
with the empty string.

Different Types of Tries

Standard Tries
Compressed/Compact Tries
Suffix Tries

Standard Tries

The standard trie for a set of strings S is


an ordered tree such that:
o each node but the root is labeled with a
character
o the children of a node are alphabetically
ordered
o the paths from the external nodes to the
root yield the strings of S

The number of children a node can have is


the size/total number of characters in the
language and all children are ordered
alphabetically.
leaf node is represented as square
Example: standard trie for the set of
strings S = { bear, bell, bid, bull, buy, sell,
stock, stop }

Diagram: Standard Tries

Applications of Standard Tries


word matching: find the first occurrence
of word X in the text
prefix matching: find the first occurrence
of the longest prefix of word X in the text

Compressed Tries

The bad thing about the standard tries is


the space requirements, to overcome we
can use the compressed tries
Compressed Trie are with the nodes of
degree at least 2
If any node has only one child, then we
can merge it into a single node

Searching(bbaa) in Compressed
Tries

Suffix Tries

A suffix trie is a compressed trie for all the


suffixes of a text

Compact representation of Suffix


Tree

Tries and Web Search Engines

The index of a search engine (collection of


all searchable words) is stored into a
compressed trie
Each leaf of the trie is associated with a
word and has a list of pages (URLs)
containing that word, called occurrence list
The trie is kept in internal memory

The occurrence lists are kept in


external memory and are ranked by
relevance
Boolean queries for sets of words (e.g.,
Java and coffee) correspond to set
operations (e.g.,intersection) on the
occurrence lists

You might also like