# Merge sort Python code you can run

> Run merge sort Python code and see why its merge algorithm writes an extra row.

Source: https://fullbytedeveloper.com/blog/merge-sort-python
Keyword: MERGE
Published here: 2026-11-23

I built this merge sort Python level so you can run it. The repository documents this command [1].

## Run merge sort Python code

```bash
python3 merge_sort.py
```

You should see groups of one merge into larger ordered groups.

## Try a merge sort Python example

```bash
python3 merge_sort.py 5 3 8 1
```

You should see the chosen row become ordered.

## Race merge sort with the other sorting levels

The arcade races every current sorting level on the same shuffled 10,000-number row. It runs each plain sorting function three times and prints the median time [1].

```bash
python3 arcade.py --race 10000
```

You should see Bubble sort, Selection sort, Insertion sort, Merge sort, Quick sort, and Heap sort with a time and extra-memory line.

## Inspect the merge sort algorithm

The level takes the smaller front value from each ordered group and writes it into a second row [2]. Compare that memory cost with [insertion sort's sorted prefix](/blog/insertion-sort-python) and [quick sort's pivot partitions](/blog/quick-sort-pivot-worst-case). The [Dev explainers topic](https://fullbytedeveloper.com/blog/topic/dev-explainers) has the series.

Send this to the friend asking why merge sort needs extra memory.

## Sources

1. [ALGO ARCADE README](https://github.com/kamilikamil/algo-arcade/blob/main/README.md)
2. [ALGO ARCADE merge sort source](https://github.com/kamilikamil/algo-arcade/blob/main/merge_sort.py)
