Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

A trie (prefix tree) with an empty root is built by inserting the words baa, ac, bbca, ba, in this order. Each node stores one character and each inserted word has its own path from the root. How many nodes does the trie contain, counting the root?

  1. A. 9
  2. B. 8
  3. C. 11
  4. D. 4

Correct answer: A. 9

Every distinct prefix (including the empty one at the root) gets exactly one node. Shared prefixes are not duplicated, so the answer is not the total number of characters inserted.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic