GATE Computer ScienceHardGATE CSE · NIELIT

Words car, card, care, cart, cat, dog, door, dot, dove, do, cargo, carbon, catalog, cat are inserted into an initially empty trie (a duplicate insertion changes nothing). Counting the root, how many nodes does the trie have?

  1. A. 28
  2. B. 25
  3. C. 23
  4. D. 32

Correct answer: B. 25

Shared prefixes are stored once; counting new characters per word (car 3, card 1, care 1, cart 1, cat 1, dog 3, door 2, dot 1, dove 2, do 0, cargo 2, carbon 3, catalog 5, cat 0) gives 24 plus the root = 25.

More Programming and Data Structures (GATE) questions

Exams that ask this topic