Worst-case Complexity of Heap Sort (MCQ: Correct Option)

Worst-case Complexity of Heap Sort (MCQ: Correct Option)

Verified Sources
Sep 13, 2026

Heap sort has a worst-case (and also average-case) time complexity of O(nlogn)O(n\log n) because it performs nn extraction steps, each involving a heap adjustment that costs O(logn)O(\log n). Therefore, the correct answer is (iii) O(nlogn)O(n\log n).

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., O(logn)O(\log n). Repeating this for nn elements yields O(nlogn)O(n\log n).

Keywords: Heap sort Max-heap Heapify-down Time complexity

Heap Sort Complexity (Build Heap + Extract + Sift Down)

Why heap sort is O(nlogn)O(n\log n) in the worst case

After the initial Build heap step, heap sort performs n1n-1 extractions. Each extraction consists of:

  1. Swap the heap root with the last element.
  2. Restore heap order using heapify-down.

The heap height is O(logn)O(\log n) for a binary heap, so the sift-down per extraction is O(logn)O(\log n) even in the worst case (when the element moved must travel from root to a leaf).

Thus, worst-case time:

T(n)=O(n)+nO(logn)=O(nlogn).T(n)=O(n)+n\cdot O(\log n)=O(n\log n).

Keywords: Binary heap Worst case Asymptotic analysis Root extraction

Heap sort runtime breakdown

  1. 1
    Step 1

    Convert the array into a valid heap (typically via bottom-up heapify). This costs O(n)O(n) in standard analysis.

  2. 2
    Step 2

    For k=nk=n down to 2: swap the root with the last unsorted element and reduce the heap size.

  3. 3
    Step 3

    Run heapify-down from the root; the element may move down at most the heap height, costing O(logn)O(\log n).

  4. 4
    Step 4

    Total time is O(n)+(n1)O(logn)=O(nlogn)O(n) + (n-1)\cdot O(\log n)=O(n\log n), so the worst case is O(nlogn)O(n\log n).

Pro Tip

When options include O(logn)O(\log n) or O(n)O(n), remember heap sort must do nn extractions, and each extraction includes an O(logn)O(\log n) heap adjustment.

Common confusion

The O(n)O(n) part comes from building the heap, but the dominating cost is the nn times heapify-down: nO(logn)=O(nlogn)n\cdot O(\log n)=O(n\log n).

Heap sort worst-case runtime components

Dominating term determines the final asymptotic complexity.

Heap sort lifecycle (high-level)

Heap Construction

Step A

Bottom-up heapify makes the array a heap."

Repeated Extraction

Step B

Swap max/min at the root to its final position."

Sift Down (Re-heapify)

Step C

Restore heap property; each sift-down takes O(logn)O(\log n). "

MCQ Answer & Rationale

Knowledge Check

Question 1 of 3
Q1Single choice

What is the worst-case time complexity of heap sort?