Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Distinct words ['caab', 'ac', 'aa', 'c', 'baab', 'bbb', 'bbca'] 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. 8
- B. 5
- C. 4
- D. 2
Correct answer: B. 5
Depth d holds one node per distinct prefix of length 2, so the count is 5. 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
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (2, 5) and must reach (0, 0) (as (row, column)). A knight…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, B–E, B–H, C–E, C–F, C–G, C–H, D–E. What is the size of…
- Distinct words ['bbba', 'aaa', 'bcaa', 'aac', 'b'] are inserted into an empty trie (one node per character, shared prefixes sharing nodes…
- A binary tree with distinct letters has preorder ACDEBF and inorder DEBCAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices B, F, A, C, D (source B, target D) with edges: B→F (2); B→A (5); A→F (-4); F→D (1); A→D (3); B→D (12)…