GATE Computer ScienceEasyGATE CS (PYQ pattern)
In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key equal to the sum of the keys of their children (a missing child counts as 0)?
- A. 4
- B. 6
- C. 5
- D. 7
Correct answer: C. 5
Check each internal node: 44 = 20 + 24, 20 = 12 + 8, 24 = 9 + 15, 9 = 4 + 5 and 15 = 0 + 15, so all five non-leaf nodes satisfy the property.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int ds(int n) { return n < 10 ? n : ds(n / 10) + n % 10; } int steps(int n) { int c = 0; while (n >= 10) { n = ds(n); c++; } return c; }…
- The keys 3, 9, 6, 12, 1, 15, 8 are inserted one after another into an initially empty max-heap (each insertion places the key at the end…
- int fib(int n) { if (n < 2) return n; return fib(n-1) + fib(n-2); } Including the initial call, how many times is fib executed in total…
- A hash table of size 13 uses double hashing with h1(k) = k mod 13, h2(k) = 1 + (k mod 11) and probe sequence (h1 + i·h2) mod 13. The keys…
- A dynamic array starts with capacity 1. Whenever an append finds it full, a new array of double the capacity is allocated and all current…
- In an AVL tree a single node has height 0. What is the minimum number of nodes in an AVL tree of height 6?