Data Structures & AlgorithmsHardGATE CS

The words graph, green, greed, grape, grass 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. 26 nodes, 4 branching
  2. B. 13 nodes, 4 branching
  3. C. 12 nodes, 4 branching
  4. D. 13 nodes, 5 branching

Correct answer: B. 13 nodes, 4 branching

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic