Q. How can you convert an array into a binary heap?
-
A.
Insert elements one by one
-
B.
Use the heapify process
-
C.
Sort the array
-
D.
Reverse the array
Solution
You can convert an array into a binary heap using the heapify process, which rearranges the elements to satisfy the heap property.
Correct Answer:
B
— Use the heapify process
Learn More →
Q. If you have a min-heap, what will be the time complexity to extract the minimum element?
-
A.
O(1)
-
B.
O(log n)
-
C.
O(n)
-
D.
O(n log n)
Solution
Extracting the minimum element from a min-heap requires re-structuring the heap, which takes O(log n) time.
Correct Answer:
B
— O(log n)
Learn More →
Q. If you want to implement a priority queue that allows for efficient decrease-key operations, which data structure would be most suitable?
-
A.
Binary Heap
-
B.
Fibonacci Heap
-
C.
Array
-
D.
Linked List
Solution
A Fibonacci heap allows for efficient decrease-key operations, making it suitable for priority queues where this operation is frequent.
Correct Answer:
B
— Fibonacci Heap
Learn More →
Q. In a binary heap, how many children does each node have at most?
Solution
In a binary heap, each node has at most two children.
Correct Answer:
B
— 2
Learn More →
Q. In a max-heap, which of the following is true about the parent and child nodes?
-
A.
Parent is always greater than children
-
B.
Parent is always less than children
-
C.
Parent can be equal to children
-
D.
None of the above
Solution
In a max-heap, the parent node is always greater than or equal to its child nodes.
Correct Answer:
A
— Parent is always greater than children
Learn More →
Q. In a max-heap, which of the following statements is true?
-
A.
The parent is always less than the children
-
B.
The parent is always greater than the children
-
C.
The children can be greater than the parent
-
D.
All elements are in sorted order
Solution
In a max-heap, the parent node is always greater than or equal to its children, maintaining the max-heap property.
Correct Answer:
B
— The parent is always greater than the children
Learn More →
Q. What is the maximum number of elements in a binary heap of height h?
-
A.
2^h
-
B.
2^(h+1) - 1
-
C.
h + 1
-
D.
h^2
Solution
The maximum number of elements in a binary heap of height h is 2^(h+1) - 1, as it is a complete binary tree.
Correct Answer:
B
— 2^(h+1) - 1
Learn More →
Q. What is the time complexity of building a binary heap from an array of n elements?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(n^2)
Solution
Building a binary heap from an array can be done in O(n) time using the heapify process.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of inserting an element into a binary heap?
-
A.
O(1)
-
B.
O(log n)
-
C.
O(n)
-
D.
O(n log n)
Solution
Inserting an element into a binary heap requires maintaining the heap property, which takes O(log n) time.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the worst-case time complexity for deleting the minimum element from a binary min-heap?
-
A.
O(1)
-
B.
O(log n)
-
C.
O(n)
-
D.
O(n log n)
Solution
Deleting the minimum element from a binary min-heap requires re-structuring the heap, which takes O(log n) time.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following algorithms can be used to sort an array using a binary heap?
-
A.
Quick Sort
-
B.
Merge Sort
-
C.
Heap Sort
-
D.
Bubble Sort
Solution
Heap Sort is an algorithm that uses a binary heap to sort an array efficiently.
Correct Answer:
C
— Heap Sort
Learn More →
Q. Which of the following is NOT a characteristic of a binary heap?
-
A.
Complete binary tree
-
B.
Heap property
-
C.
Sorted order of elements
-
D.
Dynamic size
Solution
A binary heap does not maintain a sorted order of elements; it only ensures the heap property (parent nodes are greater or less than child nodes).
Correct Answer:
C
— Sorted order of elements
Learn More →
Q. Which of the following is NOT a property of a binary heap?
-
A.
Complete binary tree
-
B.
Heap order property
-
C.
Balanced tree
-
D.
Each node has at most two children
Solution
A binary heap does not need to be a balanced tree; it only needs to be a complete binary tree.
Correct Answer:
C
— Balanced tree
Learn More →
Q. Which of the following operations can be performed in O(1) time on a max-heap?
-
A.
Insert
-
B.
Delete Max
-
C.
Get Max
-
D.
Heapify
Solution
The Get Max operation can be performed in O(1) time since the maximum element is always at the root of the max-heap.
Correct Answer:
C
— Get Max
Learn More →
Q. Which of the following operations can be performed in O(1) time on a priority queue implemented with a binary heap?
-
A.
Insert
-
B.
Delete Min
-
C.
Get Min
-
D.
Decrease Key
Solution
Getting the minimum element in a binary heap can be done in O(1) time since the minimum element is always at the root.
Correct Answer:
C
— Get Min
Learn More →
Showing 1 to 15 of 15 (1 Pages)