Tries

The word trie is an infix of the word “retrieval” because the trie can find a single word in a dictionary with only a prefix of the word.

Tries. What are they?

  • The trie is a tree where each node (vertex) represents a single word or a prefix.
  • The root represents an empty string (“”), the vertexes(nodes) that are direct sons of the root represent prefixes of length 1, the vertexes that are 2 edges of distance from the root represent prefixes of length 2, the vertexes that are 3 edges of distance from the root represent prefixes of length 3 and so on. In other words, a vertex that are k edges of distance of the root have an associated prefix of length k.
  • Let v and w be two vertexes of the trie, and assume that v is a direct father of w, then v must have an associated prefix of w.

In some Trees, nodes are given meaning by the path to them from the root node. In such trees any single node only encodes one part of the meaning; the data from all the nodes in the path must be combined to extract the complete message.

A Trie is such a tree. In a Trie each node encodes a single letter and each each path represents a word. Because it's true that there is a single path to any one node, it's fair to say that an individual node represents a word, although it only encodes a single letter. 

Check for understanding

  • What is the maximum depth of trie?
  • What is the maximum number of children for a node?
  • What is the running time of finding a word in a trie? how about insertion or deletion?
  • What's the Big O of memory storage in a trie?

Do this exercise:

https://gist.github.com/HamidAghdaee/799ad24c6d80facbdcfecdb2ea0a9ed1

Made with Slides.com