GATE Computer ScienceVery hardNIELIT Scientist B
The keys 5, 3, 8, 1, 9, 2, 7, 10, 6, 4 are inserted one at a time into an initially empty max-heap (array-based, sift-up after each insertion). How many element exchanges happen in total?
- A. 9
- B. 7
- C. 10
- D. 8
Correct answer: D. 8
Simulating each sift-up gives 8 exchanges; the final array is [10, 9, 7, 8, 4, 2, 5, 1, 6, 3].
More Algorithms questions
- How many different arrays of the distinct keys 1, 2, …, 10 are valid max-heaps (complete binary tree, parent larger than both children)?
- A 16-bit binary counter starts at 0 and is incremented 1000 times. The cost of an increment is the number of bits that change. What is the…
- Keys 1–7 are inserted into an empty BST in the order 4, 2, 6, 1, 3, 5, 7, giving a perfectly balanced tree. How many of the 5040 insertion…
- The KMP prefix (failure) function π[i] is the length of the longest proper prefix of P[0..i] that is also a suffix of it. For P =…
- Rabin–Karp searches for the digit pattern 26 in the text 3141592653589793, treating each 2-digit window as a decimal number reduced modulo…
- Jobs given as (start, finish, profit): (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,9,6), (5,9,3), (6,10,2), (8,11,4). A job may start exactly…