Data Structures & AlgorithmsHardGATE CS · Advanced

The words car, card, care, cart, cat, dog, dot, dove, do, door are stored in a trie (one letter per edge, with a flag marking the end of a word). If every chain of non-branching, non-word-ending nodes is merged into the edge above it (a compressed or radix trie), how many nodes does the compressed trie have, counting the root?

  1. A. 13
  2. B. 16
  3. C. 12
  4. D. 15

Correct answer: C. 12

Keep the root, every node that ends a word and every node with two or more children. The uncompressed trie has 16 nodes including the root; the merge removes the pure pass-through nodes, leaving 12.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic