Concept

Merge Sort is a divide-and-conquer sorting algorithm that recursively divides an array into smaller subarrays, sorts them, and then merges them back into a single sorted array. It is stable (preserves the relative order of equal elements) and widely used due to its predictable performance.

Why Use Merge Sort?

Key Characteristics

Time and Space Complexity


Divide-and-Conquer Strategy

How It Works

  1. Divide: Split the array into two roughly equal parts by finding the middle index (mid = (low + high) / 2).
  2. Recurse: Recursively apply Merge Sort to the left half (low to mid) and the right half (mid + 1 to high).
  3. Base Case: Stop dividing when a subarray has one element (already sorted).
  4. Merge: Merge the sorted subarrays into a single sorted array by comparing elements and placing them in a temporary array, then copying back to the original array.