Question 21
EasyIn a binary min-heap of n elements, how long does it take to find the minimum compared with finding an arbitrary given value?
- 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
In a binary min-heap of n elements, how long does it take to find the minimum compared with finding an arbitrary given value?
O(1) for the minimum, O(n) for an arbitrary value
O(n) for both
O(1) for both
O(log n) for both
Sign up free to see the answer and a step-by-step explanation.
Which structure is a standard way to keep the running median of a stream of numbers?
A hash set
Two heaps: a max-heap for the lower half and a min-heap for the upper half
One stack
A sorted linked list
Sign up free to see the answer and a step-by-step explanation.
Which structure efficiently merges k sorted lists?
A hash map
A stack
A queue
A min-heap holding the current front element of each list
Sign up free to see the answer and a step-by-step explanation.
How is a binary heap usually stored?
In a hash table
In a linked list of linked lists
In an array
In a file
Sign up free to see the answer and a step-by-step explanation.
Is an array sorted in ascending order always a valid min-heap?
Only for numbers below 100
Yes
No
Only if its length is even
Sign up free to see the answer and a step-by-step explanation.
By default, what kind of heap is Java's PriorityQueue?
A stack
A min-heap
A sorted list
A max-heap
Sign up free to see the answer and a step-by-step explanation.
A max-heap is stored as [9, 7, 8, 3, 5]. After the maximum (9) is removed, which value is at the root?
3
5
8
7
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of building a heap from n elements with the bottom-up heapify method?
O(n²)
O(n)
O(n log n)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
import heapq
print(heapq.nlargest(2, [4, 1, 9, 7, 8, 2]))
[8, 9]
[9, 7]
Sign up free to see the answer and a step-by-step explanation.
How do you get a max-heap from Python's heapq, which only provides a min-heap?
It isn't possible
Push the negatives of the values and negate them again when popping
Use heapq.maxheap()
Sort the list in reverse
Sign up free to see the answer and a step-by-step explanation.
[1, 2]
[9, 8]