1 / 10

Tries

Tries. A useful data structure of storing and retrieving Strings and things. Tries.

debbie
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 A useful data structure of storing and retrieving Strings and things

  2. Tries A trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings.

  3. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. 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. Values are normally not associated with every node, only with leaves and some inner nodes that correspond to keys of interest.

  4. Storing and retrieving

  5. Applications of Tries A common application of a trie is storing a predictive text or autocomplete dictionary, such as found on a mobile telephone. Such applications take advantage of a trie's ability to quickly search for, insert, and delete entries. Tries are also well suited for implementing approximate matching algorithms, including those used in spell checking and hyphenation software.

  6. Bitwise trie Tries are often sparse and are stored in a compressed manner!

  7. Trie storing digit “strings”

  8. Advantages of tries over binary search trees Looking up keys is faster. Looking up a key of length m takes worst case O(m) time. Also, the simple operations tries use during lookup, such as array indexing using a character, are fast on real machines. Tries are more space-efficient when they contain a large number of short keys, since nodes are shared between keys with common initial subsequences. Tries facilitate longest-prefix matching. The number of internal nodes from root to leaf equals the length of the key. Balancing the tree is not a big concern.

  9. Advantages of tries over hash tables: Tries support ordered iteration, whereas iteration over a hash table will result in a pseudorandom order. Tries facilitate longest-prefix matching, but hashing does not. Tries tend to be faster on average at insertion than hash tables because hash tables must rebuild their index when it becomes full - a very expensive operation. Tries therefore have much better bounded worst-case time costs. Since no hash function is used, tries are generally faster than hash tables for small keys.

  10. Drawbacks of tries Tries can be slower in some cases than hash tables for looking up data, especially if the data is directly accessed on a hard disk. Some tries can require more space than a hash table, as memory may be allocated for each character in the search string, rather than a single chunk of memory for the whole entry, as in most hash tables.

More Related