Data Structures & AlgorithmsModerateProduct-company placement

All suffixes of the string 'level' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?

  1. A. 16
  2. B. 14
  3. C. 6
  4. D. 4

Correct answer: B. 14

Each trie node spells a distinct substring, so nodes = 13 distinct non-empty substrings of 'level' + the root = 14. Ignoring shared prefixes gives 15 + 1 = 16, one node per suffix gives 6, and 4 counts the distinct letters plus the root.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic