Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Words ['bcb', 'c', 'ac', 'abbb', 'c', 'bac', 'bbb'] 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. 13
  2. B. 17
  3. C. 6
  4. D. 7

Correct answer: A. 13

Every distinct non-empty prefix is exactly one node, so there are 13 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