data-structuresautocompletebinary-treetrieternary-search-tree

Exploring a binary search tree


I figure a binary search tree is the simplest example, but really I would like to know how to explore a ternary search tree or some variety of tries. I don't have any experience with these, but I understand the concepts of adding to and searching them.

My question is, when I find a node that matches my input (like for autocomplete) how do I effectively gather all of the child nodes?


Solution

  • It depends on the implementation of your search tree. If obtaining all of the child nodes of a specific node is a common operation you need to perform, you should use an implementation that makes that operation efficient.

    For example, for each node you could store a children array which contains pointers to each of the node's children.