Data Structures & AlgorithmsHardProduct-company MCQ pattern

The words car, cart, care, cat, dog are inserted into an empty trie (one node per character, shared prefixes share nodes). How many nodes are there, NOT counting the root?

  1. A. 8
  2. B. 16
  3. C. 9
  4. D. 10

Correct answer: C. 9

c–a is shared; under a come r and t (for cat); under r come t and e; then d–o–g: c, a, r, t, e, t, d, o, g = 9 nodes. 16 is the total number of letters, ignoring sharing.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic