1 / 14

Tries

Tries. Definition. A trie is an index structure that is particulary useful when key values are of varying size. Trie is a tree of degree m >= 2 in which the branching at any level is determined not by the entire key value, but by only a potion of it.

Télécharger la présentation

Tries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tries

  2. Definition • A trie is an index structure that is particulary useful when key values are of varying size. • Trie is a tree of degree m >= 2 in which the branching at any level is determined not by the entire key value, but by only a potion of it. • When a subtrie contains only one key value, it is replaced by a node of type element.

  3. This trie contains two types of nodes: element node, and branch node. • A element node has only a data meber; • A branch node contains pointers to subtries.

  4. Since We assume that each character is one of the 26 letters of the alphabet, a branch node has 27 pointer data member;the extra pointer is used for the blank character which is used to terminate all keys.

  5. Searchinga Trie

  6. Sampling Strategies • The number of levels in the trie will depend on the strategy or key sampling technique used to determine the branching at each level. • The goal is to make a trie with the fewest numver of levels.

  7. Trie constructed for data of the preceding one sampling one character at a time, from right to left.

  8. An optimal trie for the first one trie sampling on the first level done by using the fourth character of the key values.

  9. The key value may be interpreted as consisting of digits using any radix we desire. • Using a radix of 27^2 would result in two-character sampling. • The maximum number of levels in a trie can be kept low by adopting a different strategy for element nodes.

  10. Number of levels is limited to 3; keys have been sampled from left to right, one character at a time.

  11. Insertion into a Trie • Consider the first trie and insert into it the keys bobwhite and blue jay. • First, we search bobwhite in trie and find that σ.link[‘o’] = 0. So bobwhite is not in trie and we can insert it here. • Next, search bluejay, and we find an element node contains bluebird. • The keys bluebird and blurjay are sampled until the sampling results in two different values.It happens at fifth letter.

  12. The result of insertion.

  13. Deletion from a Trie • From the preceding trie we just insert 2 key. • First we delete bobwhite. To do this we set σ.link[‘o’] = 0. No other changes need to be made. • Next let us delete bluejay. This deletion leaves us with only one key value in the subtrie δ3.That means the node δ3 may be deleted, and ρ can be moved up one level. • The same can be done for node δ2 and δ1. • Finally nodeσ is reached, and ρ cant be moved up any more levels. So we set σ.link[‘l’] = ρ.

  14. To facilitate deletion from tries, it is useful to add a count data member in each branch node.(This data member contains the number of children the node has.)

More Related