Question 1
What is a heap?
A data structure that stores data in a binary tree structure
A collection of data elements stored in an unordered manner
A stack data structure with additional constraints
A sorted collection of data elements
Question 2
Which of the following is the correct way to create a heap in Python?
heap = []
heap = [1, 2, 3, 4]
from heapq import heapify; heapify([1, 2, 3, 4])
heap = {1: 'a', 2: 'b', 3: 'c'}
Question 3
What is the time complexity of inserting an element into a heap?
O(log n)
O(n)
O(1)
O(n log n)
Question 4
Which of the following is the correct way to add an element to a heap?
heap.append(5)
heap.insert(5)
from heapq import heappush; heappush(heap, 5)
heap.add(5)
Question 5
What is the time complexity of removing the smallest element from a heap?
O(log n)
O(n)
O(1)
O(n log n)
Question 6
Which of the following is the correct way to remove the smallest element from a heap?
heap.pop()
heap.remove(0)
from heapq import heappop; heappop(heap)
heap.delete_min()
Question 7
What is the time complexity of finding the smallest element in a heap?
O(log n)
O(n)
O(1)
O(n log n)
Question 8
Which of the following is the correct way to find the smallest element in a heap?
heap[0]
min(heap)
from heapq import heappush; heappush(heap, 5)
heap.peek()
Question 9
How to get the smallest element from a heap without removing it?
heap[0]
peek_heap(heap)
heap_peak(heap)
heappop(heap)
Question 10
What is the advantage of using a heap over other data structures?
Faster insertion and removal of elements
Faster searching of elements
Requires less memory
None of the above
There are 10 questions to complete.