Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
Distinct words ['acca', 'cca', 'bb', 'ca', 'cba', 'aa'] 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 3?
- A. 12
- B. 2
- C. 3
- D. 1
Correct answer: C. 3
Depth d holds one node per distinct prefix of length 3, so the count is 3. 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
- Array A = [9, 8, 3, 6, 4, 2, 6] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (1), A–E (10), B–D (18), B–E (13), C–D (13), D–E…
- Words ['aaac', 'bac', 'cb', 'ac', 'baab', 'bc', 'bac'] are inserted in this order into an empty trie with one node per character, shared…
- Directed graph on vertices A, B, C, D, E, F with edges F→C, B→A, C→F, D→B, B→F, A→E, E→F, A→C, B→D (no weights). What is the number of…
- Array A = [3, 4, 4, 1, 1, 4, 5, 5]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→B, D→A, C→A, B→E, C→B, F→A, E→D, G→B, B→F, F→G. How many strongly connected…