Priority Queues and Heaps

Download Q&A
Q. How do you remove the maximum element from a max-heap?
  • A. Remove the root and re-heapify
  • B. Remove the last element
  • C. Swap the root with the last element
  • D. Both A and C
Q. In a min-heap, which of the following is true?
  • A. The root is the smallest element
  • B. The root is the largest element
  • C. All parent nodes are smaller than their children
  • D. Both A and C
Q. In a min-heap, which of the following statements is true?
  • A. The parent node is always greater than its children
  • B. The parent node is always less than its children
  • C. All nodes are in sorted order
  • D. The smallest element is at the bottom
Q. What is the maximum height of a binary heap with n elements?
  • A. n
  • B. log n
  • C. n log n
  • D. 2n
Q. What is the primary difference between a binary heap and a binary search tree?
  • A. Binary heaps are complete binary trees, while binary search trees are not
  • B. Binary heaps allow duplicate elements, while binary search trees do not
  • C. Binary heaps are used for priority queues, while binary search trees are used for searching
  • D. All of the above
Q. What is the primary use of a priority queue?
  • A. Sorting elements
  • B. Finding the shortest path
  • C. Managing tasks based on priority
  • D. Storing elements in a specific order
Q. What is the result of performing a 'decrease key' operation in a min-heap?
  • A. The key is increased
  • B. The key is decreased and the heap property is maintained
  • C. The key is removed
  • D. The heap is destroyed
Q. What is the result of performing a heap sort on an array?
  • A. An unsorted array
  • B. A partially sorted array
  • C. A sorted array
  • D. A reverse sorted array
Q. What is the space complexity of a binary heap storing n elements?
  • A. O(1)
  • B. O(n)
  • C. O(log n)
  • D. O(n log n)
Q. What is the space complexity of a binary heap?
  • A. O(1)
  • B. O(n)
  • C. O(log n)
  • D. O(n log n)
Q. What is the time complexity of deleting the maximum element from a max-heap?
  • A. O(1)
  • B. O(log n)
  • C. O(n)
  • D. O(n log n)
Q. What is the worst-case time complexity for building a heap from an array of n elements?
  • A. O(n)
  • B. O(n log n)
  • C. O(log n)
  • D. O(1)
Q. Which algorithm is commonly used to convert an array into a heap?
  • A. Heapify
  • B. Merge Sort
  • C. Quick Sort
  • D. Insertion Sort
Q. Which algorithm uses a priority queue to find the shortest path in a graph?
  • A. Dijkstra's Algorithm
  • B. Kruskal's Algorithm
  • C. Prim's Algorithm
  • D. Bellman-Ford Algorithm
Q. Which of the following is a characteristic of a binary heap?
  • A. Complete binary tree
  • B. Balanced binary tree
  • C. Binary search tree
  • D. Unbalanced tree
Q. Which of the following is NOT a valid implementation of a priority queue?
  • A. Array
  • B. Linked List
  • C. Binary Search Tree
  • D. Max-Heap
Q. Which of the following is true about a max-heap?
  • A. The parent node is always smaller than its children
  • B. The parent node is always larger than its children
  • C. It is a complete binary tree
  • D. Both B and C
Q. Which of the following operations can be performed in O(1) time on a priority queue implemented with a max-heap?
  • A. Insert
  • B. Delete Max
  • C. Get Max
  • D. Decrease Key
Q. Which of the following operations can be performed in O(log n) time in a binary heap?
  • A. Insertion
  • B. Deletion of the maximum element
  • C. Heapify
  • D. All of the above
Showing 1 to 19 of 19 (1 Pages)
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely