Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
Distinct words ['ca', 'b', 'bac', 'a', 'c', 'bbbb'] 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. 1
- B. 6
- C. 2
- D. 3
Correct answer: D. 3
Depth d holds one node per distinct prefix of length 2, 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
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [16, 18, 7, 19, 14, 15, 7], where Mi has size p[i−1] × p[i]…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (16), A–D (15), B–C (2), B–D (20), B–E (17), C–E…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→B (1); A→E (3); C→E (3); C→B (8); D→C (7); D→A (9); C→D (5); D→E…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges B–D, B–G, C–D, C–E, C–F. What is the size of a maximum…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 2–3, 2–4, 2–5, 0–6, 2–7, 7–8, 3–9 (parent–child). Every edge has…
- Array A = [6, 24, 27, 0, 7, 23, 30, 19]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers this…