Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
A trie keeps a counter at each node, and every word of the list W = ['bbaa', 'bc', 'a', 'cbaa', 'ccac', 'a'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'a'?
- A. 2
- B. 1
- C. 5
- D. 4
Correct answer: A. 2
Counting entries (with repeats) that start with 'a' gives 2. 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
- A binary trie of 6-bit numbers stores the set S = [25, 51, 62, 29]. For the query x = 53, what is the maximum value of x XOR s over all s…
- Directed graph on vertices A, B, C, D, E, F, G with edges C→F, F→G, F→E, A→D, E→C, C→G, B→F, A→G, B→C, G→C, A→E. How many strongly…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 0) and must reach (5, 1) (as (row, column)). A knight…
- A trie keeps a counter at each node, and every word of the list W = ['ab', 'acc', 'aac', 'bcaa', 'cab', 'ab', 'a'] is inserted once per…
- Array A = [22, 11, 12, 9, 20, 23, 25, 15, 2]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 21? (A trie with subtree counts answers…
- Array A = [17, 0, 16, 23, 30, 19, 8, 11, 10]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 13? (A trie with subtree counts answers…