31 Lecture
CS301
Midterm & Final Term Short Notes
BuildHeap
BuildHeap is an algorithm used to convert an array of elements into a heap data structure. It works by repeatedly swapping elements in the array until the entire array satisfies the heap property. The heap property ensures that the value of each
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is the time complexity of BuildHeap algorithm? a) O(n log n) b) O(n^2) c) O(n) d) O(log n)
Answer: c) O(n)
- Which data structure is created by BuildHeap algorithm? a) Array b) Linked List c) Tree d) Heap
Answer: d) Heap
- What is the maximum number of swaps required in BuildHeap algorithm? a) n-1 b) n c) n/2 d) log n
Answer: b) n
- Which sorting algorithm uses BuildHeap internally? a) Insertion Sort b) Merge Sort c) Quick Sort d) Heap Sort
Answer: d) Heap Sort
- What is the worst-case time complexity of HeapSort? a) O(n log n) b) O(n^2) c) O(n) d) O(log n)
Answer: a) O(n log n)
- Which property does a heap satisfy? a) All nodes are greater than their parent nodes b) All nodes are less than their parent nodes c) All nodes are equal to their parent nodes d) None of the above
Answer: a) All nodes are greater than their parent nodes
- What is the index of the last non-leaf node in a binary heap? a) (n-1)/2 b) (n-2)/2 c) n/2 d) n-2
Answer: b) (n-2)/2
- Which operation is used to remove the root element from a heap? a) Delete b) ExtractMin/ExtractMax c) Pop d) Remove
Answer: b) ExtractMin/ExtractMax
- Which data structure is best suited for implementing a priority queue? a) Stack b) Queue c) Heap d) Linked List
Answer: c) Heap
- What is the worst-case time complexity of inserting an element in a heap? a) O(log n) b) O(n) c) O(n log n) d) O(1)
Answer: a) O(log n)
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is the purpose of the BuildHeap algorithm? Answer: The purpose of the BuildHeap algorithm is to convert an array of elements into a heap data structure, which satisfies the heap property.
What is the time complexity of the BuildHeap algorithm? Answer: The time complexity of the BuildHeap algorithm is O(n).
How does the BuildHeap algorithm work? Answer: The BuildHeap algorithm works by repeatedly swapping elements in the array until the entire array satisfies the heap property.
What is the heap property? Answer: The heap property is a property of a binary tree where each node is greater than or equal to its children nodes.
How many swaps are required to convert an array of n elements into a heap using the BuildHeap algorithm? Answer: At most n swaps are required to convert an array of n elements into a heap using the BuildHeap algorithm.
Is the BuildHeap algorithm stable? Answer: No, the BuildHeap algorithm is not stable.
What is the space complexity of the BuildHeap algorithm? Answer: The space complexity of the BuildHeap algorithm is O(1), as the algorithm does not require any extra space beyond the input array.
What is the difference between a max heap and a min heap? Answer: In a max heap, the value of each node is greater than or equal to the value of its children, whereas in a min heap, the value of each node is less than or equal to the value of its children.
What is the time complexity of HeapSort algorithm? Answer: The time complexity of HeapSort algorithm is O(n log n).
Can the BuildHeap algorithm be used to create a priority queue? Answer: Yes, the BuildHeap algorithm can be used to create a priority queue, as a heap data structure can be used to implement a priority queue.