GATE Computer ScienceEasyGATE CS (PYQ pattern)
A 3-ary min-heap stores 1000 keys in an array A[0..999], with the children of A[i] at 3i + 1, 3i + 2 and 3i + 3. How many of the keys are at leaves?
- A. 666
- B. 667
- C. 333
- D. 750
Correct answer: B. 667
A[i] is internal iff 3i + 1 ≤ 999, i.e. i ≤ 332, giving 333 internal nodes. The other 1000 − 333 = 667 are leaves. A[332] is the last internal node (children A[997]–A[999]); the off-by-one 666 comes from taking 334 internal nodes.
More Algorithms questions
- Computing x¹²⁷ by multiplication, where each step multiplies two powers already computed (squarings count as multiplications), what is the…
- Euclid's algorithm gcd(a, b) repeatedly replaces (a, b) by (b, a mod b) until b = 0, counting one step per mod operation. Over all pairs 1…
- The Sieve of Eratosthenes on 2..100 crosses out the multiples of each prime p ≤ 10, starting from p² (p², p² + p, …). How many numbers are…
- The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs…
- Of the 92 solutions of the 8-queens problem (rotations and reflections counted separately), how many have no queen on either of the two…
- Four men m0–m3 and four women w0–w3 have preference lists (best first) m0: w1 w0 w2 w3; m1: w0 w2 w1 w3; m2: w1 w3 w2 w0; m3: w0 w1 w3 w2…