GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Keys 1..7 form a max-heap stored in a 0-indexed array (children of i are 2i+1, 2i+2). The key 5 is the third largest. In how many different array positions can it appear over all valid heaps?
- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: D. 6
Brute force over all valid max-heaps shows key 5 can occupy positions [1, 2, 3, 4, 5, 6]; the root always holds 7, so every non-root slot is possible.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A hash table starts with 7 slots, uses linear probing with h(k) = k mod size, and after each insertion, if the load factor exceeds 0.7, it…
- A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T…
- How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are…
- unsigned g(unsigned n) { return n ^ (n >> 1); } For which 8-bit n is g(n) == 0xB5? Give n in decimal.
- A routine compresses runs in place: each maximal run of a repeated character c of length L becomes c if L = 1, else c followed by the…
- A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at…