Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A max-heap is built by inserting 87, 88, 19, 50, 39, 89 one by one (sift-up on each insert). After one extract-max (move the last element to the root, then sift down), what is the array?
- A. [88, 87, 19, 50, 39]
- B. [19, 87, 88, 50, 39]
- C. [87, 50, 88, 19, 39]
- D. [89, 87, 88, 50, 39, 19]
Correct answer: A. [88, 87, 19, 50, 39]
Heap after all inserts: [89, 87, 88, 50, 39, 19]. Remove the root (89), move the last element (19) to the root and sift it down to restore the max-heap property, giving [88, 87, 19, 50, 39].
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Which traversal of a binary search tree visits the keys in ascending order?
- Which data structure does breadth-first search (BFS) use to decide which vertex to visit next?
- How many edges does a tree with n vertices have?
- In a min-heap, where is the smallest element always found?
- What is the space needed by the adjacency-matrix representation of a graph with V vertices and E edges?
- Depth-first search is naturally implemented with which of the following?