Data Structures · Question 13 · Hard

Data Structures question 13

The keys 10, 4, 7, 1 are inserted in that order into an empty array-based binary min-heap (each insert adds at the end and sifts up). What is the final array?

  1. [1, 4, 7, 10]
  2. [1, 10, 7, 4]
  3. [4, 1, 7, 10]
  4. [1, 4, 10, 7]
Answer and explanation

Answer: A. [1, 4, 7, 10]

Explanation: After 10 and 4 the heap is [4, 10]; 7 gives [4, 10, 7]. Inserting 1 at index 3 swaps it with its parent 10, then with 4, giving [1, 4, 7, 10].

Previous: The preorder traversal of a Binary Search Tree is 50, 30, 20, 40, 70, 60, 80… · Next: How many structurally different binary trees can be formed with exactly 3 nodes?

Practise data structures

Try a fresh set of data structures questions with an explanation after every answer, free and without signing up: Data Structures practice. Or sit a full placement mock test.

More data structures questions

More technical & programming practice

Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge