Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Words ['aa', 'acb', 'caa', 'caa', 'cbba', 'c'] 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. 16
- B. 6
- C. 10
- D. 5
Correct answer: C. 10
Every distinct non-empty prefix is exactly one node, so there are 10 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
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (3), A–D (3), B–D (3), C–E (3), D–E (2). An edge is CRITICAL…
- Array A = [5, 3, 5, 3, 2, 2, 4, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: A–C (1), B–C (8), B–D (5), D–E (6), C–E (7)…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(9) and count every invocation of f…
- A binary tree with distinct letters has preorder DAEFCB and inorder EADCFB. What is its postorder traversal (left, right, root), written…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–E (1), A–F (1), B–D (1), E–F (1) (weights ignored)…