Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
Words ['bcb', 'cacb', 'bbba', 'bcb', 'cbaa', 'b', 'abcc'] are inserted in this order into an empty trie with one node per character, shared prefixes sharing nodes, and a root. (A repeated word adds no nodes.) How many nodes does the trie have, not counting the root?
- A. 17
- B. 7
- C. 23
- D. 6
Correct answer: A. 17
Every distinct non-empty prefix is exactly one node, so there are 17 nodes. Counting each word's length, or each word, double-counts 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
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- A binary trie of 6-bit numbers stores the set S = [45, 4, 46, 21]. For the query x = 48, what is the maximum value of x XOR s over all s…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), A–G (1), B–G (1), C–D (1), C–F (1), C–G (1), D–E (1)…
- A binary trie of 6-bit numbers stores the set S = [23, 17, 24, 54, 21, 27, 41]. For the query x = 40, what is the maximum value of x XOR s…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 4 2 / 5 1 3. Goal board: 1 2 3 / 4 5 . A move slides a…
- Distinct words ['ca', 'a', 'ba', 'abc', 'b'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…