Oh My Algorithm
Algorithm Guidecomplexity: O(n log n)

Merge Sort

A stable divide-and-conquer algorithm with consistent performance: split the array until indivisible, then merge back while sorting.

01 Explore How It Works

Interactive Step-by-Step
Merge Sort
38
27
43
10
76
15

병합 정렬을 시작합니다. 배열을 더 이상 나눌 수 없을 때까지 절반으로 나눕니다.

Logic Node1 / 45

02 Understand It Simply

For Everyone
🔑Analogy

Keep halving, then zip the sorted pieces back together.

💡In Plain Words

Splits the array in halves, sorts each, and merges two sorted pieces in order.

Always O(n log n) and stable.

📍Where It's Used
  • Sorting that needs stability
  • external sorting of large files

03 Python Implementation

A clean, readable reference implementation of the core logic of Merge Sort.

core_implementation.py
def merge_sort(arr, low, high):
    if low < high:
        mid = low + (high - low) // 2
        merge_sort(arr, low, mid)
        merge_sort(arr, mid + 1, high)
        merge(arr, low, mid, high)

def merge(arr, low, mid, high):
    L = arr[low:mid+1]
    R = arr[mid+1:high+1]
    i = j = 0
    k = low
    while i < len(L) and j < len(R):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        arr[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        arr[k] = R[j]
        j += 1
        k += 1

04 Frequently Asked Questions

FAQ
What is Merge Sort?+

A stable divide-and-conquer algorithm with consistent performance: split the array until indivisible, then merge back while sorting.

What is the time complexity of Merge Sort?+

The time complexity of Merge Sort is O(n log n). Follow the step-by-step visualization to see exactly why.

Where is Merge Sort used?+

Sorting that needs stability, external sorting of large files.

What's a simple analogy for Merge Sort?+

Keep halving, then zip the sorted pieces back together.

Guide Progress0%