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?
- A. 16
- B. 14
- C. 6
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A DAG on vertices A–G has edges A→D, A→F, C→D, E→C, F→B, F→D, G→A, G→F. What order does Kahn's algorithm with a FIFO queue (initial zero…
- What is the edit distance (insert, delete, substitute; each cost 1) between DIAMETER and INTERVAL?
- Prim's algorithm starts at F on the weighted undirected graph A–B (18), A–F (15), B–E (26), B–F (23), B–G (21), C–D (9), C–E (16), D–E…
- A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 1, 2, 5, 14, 16, 22, 24, 25. What is…
- An undirected graph has edges A–B, A–C, A–D, B–F, B–G, C–E, D–F, E–F, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- Coins of denominations 1, 4, 7, 8 are available in unlimited supply. What is the minimum number of coins needed to make 38, and how many…