1 / 7

Lexicographic Search:Tries

Lexicographic Search:Tries. All of the searching methods we have seen so far compare entire keys during the search Idea: Why not consider a key to be a sequence of characters (letters or digits, for example) and use these characters to determine a multiway branch at each step

Download Presentation

Lexicographic Search: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. Lexicographic Search:Tries • All of the searching methods we have seen so far compare entire keys during the search • Idea: Why not consider a key to be a sequence of characters (letters or digits, for example) and use these characters to determine a multiway branch at each step • If the keys are alphabetic names (names), we make a 29-way branch at each step. • If the keys are natural numbers in base 10, we make a 10 way branch at each step • Similar to a thumb index in a dictionary • Called Retrieval -- pronounced like “try”

  2. 0 Tries - Example • Assume that we have the following keys in a trie: • 0, 10, 11, 100, 101, 110, 2, 21 • Notice that the rootdoes not store actual data 0 1 2 3 4 5 6 7 8 9 2 10 11 21 110 100 101

  3. 0 110 Tries - Search • Search 110: 0 1 2 3 4 5 6 7 8 9 2 10 11 21 110 100 101

  4. 0 2195 Tries - Insertion • Insert 2195 into the following trie: 0 1 2 3 4 5 6 7 8 9 2 10 11 21 110 100 101

  5. 0 2195 Tries - Deletion • Delete 10 from the following trie: 0 1 2 3 4 5 6 7 8 9 2 10 11 21 110 100 101

  6. 0 2195 Tries - Deletion • Delete 110 from the following trie: 0 1 2 3 4 5 6 7 8 9 2 21 110 100 101

  7. Tries: Summary • # of steps requires to search a trie (or to insert into it) is proportional to the number of characters making up a key • E.g., if we have numbers in the range 0 – 999999, then we have at most 6 steps (comparisons) to reach a key • If the number of chars is small relative to the logarithm 2 of the number of keys, a trie may be superior to a binary search tree • E.g., if keys consist of all 999999 numbers in the range 0-999999, we have at most 6 steps to reach a key, whereas a binary search tree would take log2(999999) ~ 20 steps (key comparisons) • The best solution may be to combine the methods • A trie can be used in the fist few chars of the key, and then another method can be used for the remainder of the key

More Related