Question 41
MediumA max-heap has 15 elements. At which array indexes (0-indexed) can the minimum element be?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
A max-heap has 15 elements. At which array indexes (0-indexed) can the minimum element be?
Only at index 0
Only at the leaves, indexes 7 to 14
Only at index 14
Anywhere
Sign up free to see the answer and a step-by-step explanation.
What is the height (levels) of a binary heap with 1,000 elements?
9
11
500
10
Sign up free to see the answer and a step-by-step explanation.
Why does bottom-up heapify run in O(n) rather than O(n log n)?
Most nodes are near the bottom and sift down only a short distance
It skips half the elements
It doesn't compare elements
It uses recursion
Sign up free to see the answer and a step-by-step explanation.
Which problem is solved with two heaps (a max-heap and a min-heap)?
Keeping the running median of a stream
Sorting a linked list
Finding a cycle
Binary search
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of merging k sorted lists with a total of n elements using a min-heap?
O(n log k)
O(n log n) always
O(nk)
O(k log n)
Sign up free to see the answer and a step-by-step explanation.
Is a sorted array (increasing) a valid min-heap?
Only if its length is a power of 2
Yes, every parent is smaller than its children
Only if it has no duplicates
No, never
Sign up free to see the answer and a step-by-step explanation.
Is [10, 9, 8, 7, 6, 5, 4] a valid max-heap?
No, because 4 is at the end
No, a heap cannot be sorted
Yes
No, because 9 > 8 is out of order
Sign up free to see the answer and a step-by-step explanation.
Which is NOT efficient in a binary min-heap?
Searching for an arbitrary value
Finding the minimum
Removing the minimum
Inserting a value
Sign up free to see the answer and a step-by-step explanation.
Which algorithm uses a priority queue to choose the next closest vertex?
Depth-first search
Kruskal's union–find only
Dijkstra's algorithm
Binary search
Sign up free to see the answer and a step-by-step explanation.
A task scheduler always runs the job with the earliest deadline. Which data structure suits it?
An unsorted array
A stack
A FIFO queue
A min-heap keyed by deadline
Sign up free to see the answer and a step-by-step explanation.