GATE Computer ScienceModerateGATE CS (PYQ pattern)

The words tea, ten, to, inn, in, i, ted, tent, tenant, tens, ton are inserted into an initially empty trie (one node per character, root not counted; a word end is just a marker on an existing node). How many nodes does the trie have?

  1. A. 18
  2. B. 15
  3. C. 13
  4. D. 34

Correct answer: B. 15

Shared prefixes are stored once: t-e-a, t-e-n(-t-(a-n-t)), t-e-d, t-e-n-s, t-o(-n), i-n-n gives 15 nodes, against 34 characters in total.

More Programming and Data Structures (GATE) questions

Exams that ask this topic