Question discussion

The keys 5, 3, 8, 1, 9, 2 are inserted one by one into an initially empty binary min-heap stored in an array (each new key is placed at the…

1918Medium DSSSB TGT Computer Science 0 replies 1 views
0

The keys 5, 3, 8, 1, 9, 2 are inserted one by one into an initially empty binary min-heap stored in an array (each new key is placed at the end and moved up while it is smaller than its parent). What is the final array?

  • A1 3 2 5 9 8
  • B1 2 3 5 9 8
  • C1 3 8 5 9 2
  • D1 3 2 9 5 8
Correct answer: A

Explanation

After 1 is inserted the array is 1 3 8 5; adding 9 gives 1 3 8 5 9; adding 2 at the end swaps it with its parent 8, giving 1 3 2 5 9 8.

Discussion 0

Nobody has replied yet. Start the discussion!