Data Structures & AlgorithmsHardGATE CS · Product-company placement

The words trial, tripod, trie, trip, tried, tree 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. 29 nodes, 2 branching
  2. B. 12 nodes, 2 branching
  3. C. 13 nodes, 3 branching
  4. D. 13 nodes, 2 branching

Correct answer: D. 13 nodes, 2 branching

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic