Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Distinct words ['aac', 'cb', 'ba', 'bc', 'a'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a root). How many leaves does the trie have? A leaf is a node with no children, and the root counts only when it has no children.

  1. A. 1
  2. B. 4
  3. C. 3
  4. D. 5

Correct answer: B. 4

A leaf is the end of a word that no other word extends, and there are 4 such words. Counting every word, or words that are proper prefixes of another, is the usual mistake.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic