Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
A trie keeps a counter at each node, and every word of the list W = ['bb', 'bba', 'aabc', 'ac', 'aba', 'bbc', 'aab', 'ac'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'a'?
- A. 4
- B. 2
- C. 6
- D. 5
Correct answer: D. 5
Counting entries (with repeats) that start with 'a' gives 5. Counting distinct words, substring matches, or suffix matches are different questions.
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→F, E→A, C→D, D→C, D→B, B→C, A→C, A→D, B→D (no weights). What is the number of…
- A binary tree with distinct letters has preorder CHEGDBFA and inorder HECFBADG. What is its postorder traversal (left, right, root)…
- Directed graph on vertices A, B, C, D, E, F, G with edges G→E, A→D, F→A, G→F, C→E, B→E, A→B, B→G, E→G, A→C (no weights). What is the…
- Coins of denominations [12, 11, 5, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 34?…
- Array A = [7, 13, 13, 9, 9, 3, 1, 11]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in…
- Array A = [17, 22, 23, 7, 20, 4] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 6?