Mechanism (Divide and Conquer)

  1. Divide: recursively split the array into halves until each sub-array has 1 element
  2. Conquer: merge sorted sub-arrays back together by repeatedly comparing front elements

Pseudocode

MERGE_SORT(arr, low, high):
  IF low < high:
    mid = (low + high) / 2
    MERGE_SORT(arr, low, mid)
    MERGE_SORT(arr, mid+1, high)
    MERGE(arr, low, mid, high)

Complexity

Exam Angle / MCQ Trap

Merge Sort's guaranteed O(n log n) worst-case makes it preferred for linked lists (no random access penalty) and for external sorting (large datasets that don't fit in memory). Its O(n) space cost is the classic trade-off point examiners test against Quick Sort's O(log n) space but O(n²) worst case.

📌 Sample & Repeated FPSC Questions (2016–2026)

2026, Paper I, Q5(b) (6 marks) — What is the difference between Time Complexity and Space Complexity? Explain with examples.

Time complexity measures how the number of basic operations grows with input size n (asymptotic, hardware-independent). Space complexity measures how much extra working memory (beyond the input) an algorithm needs as a function of n.

Key reasoning points: