Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
Words ['b', 'b', 'b', 'c', 'cbca', 'aca'] 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. 6
- B. 11
- C. 8
- D. 4
Correct answer: C. 8
Every distinct non-empty prefix is exactly one node, so there are 8 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
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–D (5), B–D (7), B–F (13), C–D (11), D–E (11), D–F (12), E–F…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→F, C→G, B→E, E→D, E→G, C→E, F→D, C→A, D→A, F→E. How many strongly connected…
- Directed graph on vertices A, B, C, D, E, F with edges C→F, D→E, D→B, F→B, F→C, E→C, F→E, E→A (no weights). What is the number of vertices…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (6), A–C (1), A–D (1), B–C (3), B–D (6), C–D (4). Among all…
- Keys are inserted in the order 78 11 62 12 89 into an empty binary search tree. Then the key 78 (which has two children) is deleted by…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…