Data Structures & AlgorithmsHardGATE CS · Product-company placement

The words stem, stack, step, star, start 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. 23 nodes, 3 branching
  2. B. 10 nodes, 3 branching
  3. C. 11 nodes, 3 branching
  4. D. 11 nodes, 4 branching

Correct answer: C. 11 nodes, 3 branching

Nodes = distinct non-empty prefixes + root = 10 + 1 = 11, 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