1 / 14

15-211 Fundamental Data Structures and Algorithms (Spring ’05)

15-211 Fundamental Data Structures and Algorithms (Spring ’05). Recitation Notes: Tries Slides prepared by Uri Dekel, udekel@cs Based on recitation notes by Will Haines. Radix Sort. A bucket-based sorting algorithm Input: elements with digits in longest key Algorithm:

efrat
Télécharger la présentation

15-211 Fundamental Data Structures and Algorithms (Spring ’05)

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. 15-211 Fundamental Data Structures and Algorithms(Spring ’05) Recitation Notes: Tries Slides prepared by Uri Dekel, udekel@cs Based on recitation notes by Will Haines

  2. Radix Sort • A bucket-based sorting algorithm • Input: elements with digits in longest key • Algorithm: • From least-significant digit to most significant • Place into bins by current digit while preserving original order (“stable sort”) • Append bins into a sequence • Sort time complexity: 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  3. Radix sort example • Input: {115, 364,112, 003, 087, 006, 091, 911} • Phase 1: {091, 911, 112, 003, 364, 115, 006, 087} • Phase 2: {003, 006, 911, 112, 115, 364, 087, 091} • Phase 3: {003, 006, 087, 091, 112, 115, 364, 911} 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  4. Tries • Based on the same principle as radix sort • Create an -level tree • Support search in 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  5. Multiway Tries with values at predefined depth • Every internal node has |A| pointers • |A| is the size of the “alphabet” • |A|=10 for decimal digits 0..9 • |A|=26 for the English alphabet • The -th level nodes point to leafs that contain actual value of key • Limitations: • All keys must have exactly digits • Search time is • One key cannot be a prefix of another key • Significant time/space tradeoff • Lots of wasted space but the tree is very shallow 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  6. Multiway Tries with values at unknown depth • Allows searching for -digit key in • Even if longest key is digits • Add one “terminal” signal cell to each node • Indicates that the key entered so far is a member of the collection • Allows us to go on searching for longer key 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  7. Digital Trie example • Input sequence: {0, 2, 10, 011, 01, 20, 21} • We use three digit buckets and one for signal 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  8. Digital Trie example • Search for “2”: Hit! 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  9. Digital Trie example • Search for “01”: Hit! 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  10. Digital Trie example • Search for “011”: Hit! 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  11. Digital Trie example • Search for “1”: Miss (within trie) 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  12. Digital Trie example • Search for “22”: Miss (runs off of tree) 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  13. Hashmap Tries • What if we don’t know the digits of our alphabet? • e.g., in HW2 we will have individual words as “digits” of the search tree • We will associate them with final words to complete phrases • We use a hashmap at each node • Amortized constant lookup at each node • Amortized constant insert at each node 15-211 Recitation notes on tries, Uri Dekel and Will Haines

  14. Hashmap Trie Example • Store frequency of all 3-word sequence • Input sentence: “in at the ox at the in the in at ox at ox in the at the in at in ox the ox at the ox” 15-211 Recitation notes on tries, Uri Dekel and Will Haines

More Related