Trie saves space, but how?

前端 未结 5 862
离开以前
离开以前 2021-02-07 13:05

I am confused as to how the Trie implementation saves space & stores data in most compact form!

If you look at the tree below. When you store a character at any nod

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 13:39

    Guava may indeed store the key at each level but the point to realize is that the key does not really need to be stored because the path to the node completely defines the key for that node. All that actually needs to be stored at each node is a single boolean indicating whether this is a leaf node or not.

    Tries, like any other structure, excel at storing certain types of data. Specifically, tries are best at storing strings that share a common root. Think of storing full-path directory listings for example.

提交回复
热议问题