Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
A trie (prefix tree) with an empty root is built by inserting the words bccc, abb, c, bcba, c, in this order. Each node stores one character and each inserted word has its own path from the root. How many nodes does the trie contain, counting the root?
- A. 10
- B. 4
- C. 11
- D. 13
Correct answer: C. 11
Every distinct prefix (including the empty one at the root) gets exactly one node. Shared prefixes are not duplicated, so the answer is not the total number of characters inserted.
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
- A trie (prefix tree) with an empty root is built by inserting the words cca, bbb, ccbb, in this order. Each node stores one character and…
- A trie (prefix tree) with an empty root is built by inserting the words cab, cabb, cb, cc, in this order. Each node stores one character…
- A trie (prefix tree) with an empty root is built by inserting the words ca, bbaa, c, ba, in this order. Each node stores one character and…
- Count the inversions in the permutation [8, 6, 4, 5, 2, 7, 3, 1]: pairs of positions i < j with p[i] > p[j].
- Count the inversions in the permutation [8, 2, 7, 4, 3, 5, 9, 11, 10, 6, 1]: pairs of positions i < j with p[i] > p[j].
- Count the inversions in the permutation [5, 9, 10, 4, 1, 6, 8, 3, 7, 2]: pairs of positions i < j with p[i] > p[j].