unit5_trie
unit5_trie
Balanced Tree
AVL Tree
Red Black Tree
Multi way search Tree
B- Tree
Binary Trie
Multi-way Trie
Suffix Tree
Trie data structure
What is a Trie data structure?
Trie is also known as the digital tree or prefix tree. The position of a node in
the Trie determines the key with which that node is connected.
Properties of the Trie for a set of the
string:
The root node of the trie always represents the null node.
Each child of nodes is sorted alphabetically.
Each node can have a maximum of 26 children (A to Z).
Each node (except the root) can store one letter of the alphabet.
Basic operations of Trie
There are three operations in the Trie:
Insertion of a node
Searching a node
Deletion of a node
3. Browser history
It is also used to complete the URL in the browser. The browser keeps a history of the
URLs of the websites you've visited.
Trie
Advantages of Trie
It can be insert faster and search the string than hash tables and binary
search trees.
It provides an alphabetical filter of entries by the key of the node.
Disadvantages of Trie
It requires more memory to store the strings.
It is slower than the hash table.
Multiway tries
A binary trie uses radix search with radix 2; a multiway trie uses radix search with
radix R > 2
multiway tries are sometimes called R-ary tries
If each digit in a key has r bits, the radix is R = 2 r , and if keys have at most B bits,
the worst-case number of comparisons would be only B/r
However, to implement this idea, a node in the trie must be able to have as many
as R children
Examples:
Keys are words made up of lower-case letters in English. There are 26 different lower-
case letters in English, so a R-ary trie with R=26 could hold these keys. (This specific
variant is sometimes called an “alphabet trie”)
Keys are decimal integers made up of decimal digits. There are 10 different decimal
digits, so a R-ary trie with R=10 could hold these keys
Keys are 128-bit IEEE high precision floating point numbers. Consider each as made up of
32 4-bit nybbles. There are 2 4 = 16 different nybble values, so a R-ary trie with R=16
could hold these keys (note that lexicographic ordering of such keys is not the same as
their numeric ordering)
Suffix tree
In algorithms for string processing and pattern matching, a suffix tree is a type of
data structure. It allows for quick pattern searching and other string-related
activities by compactly representing all the suffixes of a given string
. It was first introduced by Ukkonen in 1995 and is now a key idea in bioinformatics
and computer science.
Trie is simply an expanded version of the suffix tree.
It is a trie that has all of a string's suffixes compressed into it.
Suffix trees can be used to address several string-related issues.
Pattern matching, spotting distinctive substrings within a string, and figuring out
the longest palindrome are a few of these issues.
A suffix is a substring that consists of all the characters in the string from a
particular location to the very end.
For instance, the suffixes for the string "banana" are "banana," "nana," "nana," "ana,"
"na," and "a." These suffixes are all stored in a tree-like data structure called a suffix tree.
An ordered tree data structure called a trie is effective at storing a dynamic set of strings.
Each edge of a suffix tree corresponds to a single character, and the pathways from the
root to the leaves make up the suffixes of the starting string.
And a compressed trie for the given set of strings
will look like:
What is a B Tree?
In order to ensure that none of the properties of a B Tree data structure are
violated during the operations, the B Tree may be split or joined. The
following are some operations that we can perform on a B Tree:
Searching a data element in B Tree
Insertion of a data element in B Tree
Deletion of a data element in B Tree
Searching Operation on a B
Tree
Step 1: The search begins from the root node. Compare the search
element, k, with the root.
Step 1.1: If the root node consists of the element k, the search will be complete.
Step 1.2: If the element k is less than the first value in the root, we will move to
the leftmost child and search the child recursively.
Step 1.3.1: If the root has only two children, we will move to the rightmost child
and recursively search the child nodes.
Step 1.3.2: If the root has more than two keys, we will search the rest.
Step 2: If the element k is not found after traversing the whole tree, then
the search element is not present in the B Tree.
Let us visualize the above steps with the help of an example.
Suppose that we wanted to search for a key k=34 in the following B Tree:
Let us visualize the above steps with the help of an example.
Suppose that we wanted to search for a key k=34 in the following B Tree:
Let us visualize the above steps with the help of an example.
Suppose that we wanted to search for a key k=34 in the following B Tree:
We compared the key with four different values in the above example until we found
it. Thus, the time complexity required for the search operation in a B Tree is O(log?n).