Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
Distinct words ['baab', 'bcb', 'cbaa', 'ccba', 'bbaa', 'ab', 'aac'] are inserted into an empty trie (one node per character, shared prefixes sharing nodes, root at depth 0). How many nodes are at depth exactly 2?
- A. 6
- B. 7
- C. 10
- D. 1
Correct answer: B. 7
Depth d holds one node per distinct prefix of length 2, so the count is 7. Counting only the words of that length misses the shared prefixes.
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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–B (1), A–E (1), A–G (1), C–F (1), C–G (1), D–F (1), D–H (1)…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–D (2), A–E (3), A–F (6), B–D (9), B–F (5), C–F (5), D–E (2), E–F (9)…
- Words ['b', 'c', 'babb', 'accc', 'aaa', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–D (16), A–E (3), B–C (6), B–E (16), C–D (2), C–E (14). What is…
- Words ['cb', 'da', 'abb', 'dbd', 'cd'] (each may be used at most once). A chain is a sequence of these words in which the first letter of…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (2), A–C (3), A–D (3), B–C (3), B–D (2), C–D (3). How many distinct…