Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
Distinct words ['baa', 'c', 'b', 'bac', 'bba', 'cbbc'] 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. 3
- B. 1
- C. 4
- D. 9
Correct answer: C. 4
Depth d holds one node per distinct prefix of length 3, so the count is 4. 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
- Directed graph on vertices A, B, C, D, E, F with edges E→D, A→D, F→C, E→C, A→E, B→C, A→F, D→A. How many strongly connected components does…
- Strings a = "bbbab" and b = "cccbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Coins of denominations [6, 5, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 16? (Coins…
- Words ['b', 'a', 'aaba', 'cab', 'baca', 'b'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Array A = [30, 20, 28, 25, 2, 19, 15, 7, 11]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–F (1), A–G (1), B–C (1), B–E (1), C–E (1), D–E (1), E–H (1)…