Data Structures & AlgorithmsHardProduct-company placement

The words stem, stall, stamp, star, step are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a root). How many nodes does the trie have (including the root), and how many nodes have two or more children?

  1. A. 12 nodes, 3 branching
  2. B. 23 nodes, 3 branching
  3. C. 11 nodes, 3 branching
  4. D. 12 nodes, 4 branching

Correct answer: A. 12 nodes, 3 branching

Nodes = distinct non-empty prefixes + root = 11 + 1 = 12, not the total letter count 22. A node branches when two different next letters follow its prefix; there are 3 such nodes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic