Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Five numbers 1, 2, 3, 4, 5 are inserted in that order into an initially empty min-heap (array form, sift-up after each insertion). How many swaps are performed in total?
- A. 0
- B. 1
- C. 2
- D. 3
Correct answer: A. 0
Inserting an increasing sequence into a min-heap never triggers a swap, because each new value is larger than its parent. The count is zero, the trap being to assume each insertion swaps at least once.
More Coding Interview Problems questions
- Problem: Binary search for the value 77 in the sorted list 1, 2, ..., 100 uses the midpoint mid = (lo + hi) // 2 and the inclusive range…
- Problem: What is the value of the lowest set bit of 96 (the largest power of 2 dividing 96)?
- Problem: For the numbers 1, 2, 3, 4, 5, how many unordered pairs (i, j) with i < j have i XOR j strictly less than 4?
- Problem: What is the sum of the proper divisors of 220 (divisors less than 220)?
- Problem: What is the smallest positive integer n such that 1 + 2 + … + n is divisible by 10?
- Problem: Compute 7^100 mod 13.