Worst-case Complexity of Heap Sort (MCQ: Correct Option)
Heap sort has a worst-case (and also average-case) time complexity of because it performs extraction steps, each involving a heap adjustment that costs . Therefore, the correct answer is (iii) .
Key idea: after building a max-heap, each delete/extract-max requires “sift-down” (heapify-down) which traverses at most the height of the heap, i.e., . Repeating this for elements yields .
Keywords: Heap sort Max-heap Heapify-down Time complexity
Heap Sort Complexity (Build Heap + Extract + Sift Down)
Why heap sort is in the worst case
After the initial Build heap step, heap sort performs extractions. Each extraction consists of:
- Swap the heap root with the last element.
- Restore heap order using heapify-down.
The heap height is for a binary heap, so the sift-down per extraction is even in the worst case (when the element moved must travel from root to a leaf).
Thus, worst-case time:
Keywords: Binary heap Worst case Asymptotic analysis Root extraction
Heap sort runtime breakdown
- 1Step 1
Convert the array into a valid heap (typically via bottom-up heapify). This costs in standard analysis.
- 2Step 2
For down to 2: swap the root with the last unsorted element and reduce the heap size.
- 3Step 3
Run heapify-down from the root; the element may move down at most the heap height, costing .
- 4Step 4
Total time is , so the worst case is .
Pro Tip
When options include or , remember heap sort must do extractions, and each extraction includes an heap adjustment.
Common confusion
The part comes from building the heap, but the dominating cost is the times heapify-down: .
Heap sort worst-case runtime components
Dominating term determines the final asymptotic complexity.
Heap sort lifecycle (high-level)
Heap Construction
Step ABottom-up heapify makes the array a heap."
Repeated Extraction
Step BSwap max/min at the root to its final position."
Sift Down (Re-heapify)
Step CRestore heap property; each sift-down takes . "
MCQ Answer & Rationale
Knowledge Check
What is the worst-case time complexity of heap sort?
Explore Related Topics
Complexity Analysis: Best Case, Worst Case, and Average Case
The material introduces best‑case, worst‑case, and average‑case complexity as three distinct functions describing an algorithm’s running time on inputs of size , explains how they are formally defined, and shows why worst‑case analysis is usually preferred.
- Best case: , the minimum time over all inputs of size .
- Worst case: , giving a guaranteed upper bound.
- Average case: , requiring an explicit input probability model.
- Linear search illustrates the three cases: best, worst, and average (expected comparisons).
- Worst‑case analysis is favored because it needs no probabilistic assumptions and ensures reliability for all inputs, especially in real‑time or safety‑critical systems.
Applications of the Queue Data Structure (MCQ: Which option is correct?)