Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
A trie keeps a counter at each node, and every word of the list W = ['c', 'accb', 'bbcb', 'c', 'cacb', 'b', 'bccb', 'c'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'c'?
- A. 7
- B. 4
- C. 3
- D. 2
Correct answer: B. 4
Counting entries (with repeats) that start with 'c' gives 4. 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
- Array A = [7, 11, 5, 8, 11, 8]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–E (1), B–D (1), B–F (1), C–D (1), C–F (1), D–E (1), D–F (1)…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 4 1 / 2 5 3. Goal board: 1 2 3 / 4 5 . A move slides a…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (2), A–E (2), B–C (2), C–D (1), C–E (3). How many distinct…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (3), A–C (3), B–C (3), B–D (3), C–D (1), C–E (4). Among all…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), A–E (1), B–D (1), B–E (1), B–G (1), C–D (1), C–H (1)…