All mock tests are FREE till 31 December — register to save your progress

Consider the following statements about the heap sort algorithm:
A. The MAX-HEAPIFY procedure, which runs in O(lg n) time, is the key to maintaining the max-heap property.
B. The BUILD-MAX-HEAP procedure, which runs in O(lg n) time, produces a max-heap from an unordered input array.
C. The MAX-HEAP-INSERT procedure, which runs in O(lg n) time, implements the insertion operation.
D. The HEAP-INCREASE-KEY procedure runs in O(n lg n) time to set the key of a new node to its correct value.
Choose the correct answer from the options given below:

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. A, C only

Explanation

Per CLRS, MAX-HEAPIFY is O(lg n), BUILD-MAX-HEAP is O(n) (not O(lg n)), MAX-HEAP-INSERT is O(lg n) and HEAP-INCREASE-KEY is O(lg n). So A and C are true.

More Data Structures and Algorithms questions