Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional

Words ['b', 'c', 'babb', 'accc', 'aaa', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes sharing nodes, and a root. (A repeated word adds no nodes.) How many nodes does the trie have, not counting the root?

  1. A. 6
  2. B. 5
  3. C. 11
  4. D. 14

Correct answer: C. 11

Every distinct non-empty prefix is exactly one node, so there are 11 nodes. Counting each word's length, or each word, double-counts shared prefixes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic