Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
Distinct words ['bbba', 'aaa', 'bcaa', 'aac', 'b'] 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. 5
- B. 4
- C. 3
- D. 0
Correct answer: C. 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 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)…
- Distinct words ['cc', 'aab', 'a', 'cbc', 'bbb', 'bc'] are inserted into an empty trie (one node per character, shared prefixes share…
- Directed weighted graph on vertices F, E, D, B, C (source F, target C) with edges: F→E (5); F→D (8); D→E (-5); E→C (1); D→C (6); F→C (8)…
- A trie keeps a counter at each node, and every word of the list W = ['c', 'b', 'baba', 'a', 'b', 'cc', 'ccb', 'cb'] is inserted once per…
- Strings a = "accca" and b = "bcbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…