Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
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 occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'b'?
- A. 2
- B. 5
- C. 4
- D. 3
Correct answer: D. 3
Counting entries (with repeats) that start with 'b' gives 3. 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
- Strings a = "accca" and b = "bcbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Directed graph on vertices A, B, C, D, E, F, G with edges D→A, A→E, E→F, B→F, B→A, F→G, C→D, D→G, E→B, A→F, A→B (no weights). What is the…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges A–D, A–F, B–D, B–F, B–G. What is the size of a maximum…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→C (9); C→D (5); C→E (4); A→C (5); B→E (1); C→A (3); E→A (2); B→C…
- Keys [43, 27, 29, 8, 44, 17, 18, 5, 4] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Directed weighted graph on vertices F, E, D, A, B (source F, target B) with edges: F→E (4); F→D (6); D→E (-3); E→B (1); D→B (6); F→B (11)…