Data Structures & Algorithms Multiple Choice Questions on “Heapsort – 1”.
1. On which algorithm is heap sort based on?
a) Fibonacci heap
b) Binary tree
c) Priority queue
d) FIFO
Answer: c
Clarification: Heap sort is based on the algorithm of priority queue and it gives the best sorting time.
2. In what time can a binary heap be built? Answer: a 3. Heap sort is faster than Shell sort. 4. Consider the following heap after buildheap phase. What will be its corresponding array? 5. In what position does the array for heap sort contains data? Answer: a 6. In heap sort, after deleting the last minimum element, the array will contain elements in? 7. What is the typical running time of a heap sort algorithm? 8. How many arrays are required to perform deletion operation in a heap? Answer: b 9. What is the time taken to perform a delete min operation? Answer: c 10. Heap sort is an extremely stable algorithm. Answer: a 11. What is the average number of comparisons used in a heap sort algorithm? Answer: d 12. What is the time taken to copy elements to and from two arrays created for deletion? Answer: a 13. What is the average number of comparisons used to heap sort a random permutation of N distinct items?
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Clarification: The basic strategy is to build a binary heap of N elements which takes O(N) time.
a) true
b) false
Answer: b
Clarification: Heap sort is slower than Shell sort because Shell sort uses Sedgewick’s increment sequence.
a) 26,53,41,97,58,59,31
b) 26,31,41,53,58,59,97
c) 26,41,53,97,31,58,59
d) 97,53,59,26,41,58,31
Answer: d
Clarification: Constructing a max heap using the elements 97,53,59,26,41,58,31 will cause the heap to look like that.
a) 0
b) 1
c) -1
d) anywhere in the array
Clarification: The array for heap sort contains data at position 0 whereas for a binary heap, array begins at 1. This is the reason for its complexity.
a) increasing sorting order
b) decreasing sorting order
c) tree inorder
d) tree preorder
Answer: b
Clarification: By logic, after deleting minimum element, the heap will contain elements in decreasing sorting order. We can change this by altering the ordering property.
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Answer: b
Clarification: The total running time of a heap sort algorithm is mathematically found to be O(N log N).
a) 1
b) 2
c) 3
d) 4
Clarification: To perform deletion operation in a heap, we require 2 arrays and that occupies extra memory space and hence increase in running time.
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Clarification: The time taken to perform a deletion of a minimum element is mathematically found to be O( log N).
a) true
b) false
View Answer
Clarification: Heap sort uses fewer comparisons than other sorting algorithms and hence it is an extremely stable algorithm.
a) N log N-O(N)
b) O(N log N)-O(N)
c) O(N log N)-1
d) 2N log N + O(N)
View Answer
Clarification: The average number of comparisons in a heapsort algorithm is mathematically found to be 2N log N + O(N).
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Clarification: The time taken to copy elements to and from the main array and extra array is found to be O(N).
a) 2N log N-O(N)
b) 2N log N-O(N log N)
c) 2N log N-O(N log log N)
d) 2N log N-O(log N)
Answer: c
Clarification: According to a theorem, the average number of comparisons used to heap sort a random permutation of N distinct items is found to be 2N log N-O(N log log N).