Data Structures & AlgorithmsHardProduct-company MCQ pattern
The words car, cart, care, cat, dog are inserted into an empty trie (one node per character, shared prefixes share nodes). How many nodes are there, NOT counting the root?
- A. 8
- B. 16
- C. 9
- D. 10
Correct answer: C. 9
c–a is shared; under a come r and t (for cat); under r come t and e; then d–o–g: c, a, r, t, e, t, d, o, g = 9 nodes. 16 is the total number of letters, ignoring sharing.
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
- How many calls in total (including the first) does C(5, 2) make? c int C(int n, int k) { if (k == 0 || k == n) return 1; return C(n - 1, k…
- For n = 6, how many disk moves does this Tower of Hanoi function count, and how many calls of hanoi are made in total? c int hanoi(int n…
- A robot moves only right or down on a 3 × 4 grid of cells (3 rows, 4 columns) from the top-left cell to the bottom-right cell. The cell in…
- What is the length of the longest palindromic SUBSEQUENCE of CHARACTER?
- Coins of 1, 5, 6 and 8 are available in unlimited supply. For amount 11, how many coins does the 'largest coin first' greedy method use…
- Each job takes 1 unit of time; only one job runs at a time. Jobs (deadline, profit): J1 (2, 100), J2 (1, 19), J3 (2, 27), J4 (1, 25), J5…