Merge sort Python code you can run
Run merge sort Python code and see why its merge algorithm writes an extra row.
Published here · 2 sources · Resume reading
I built this merge sort Python level so you can run it. The repository documents this command [1].
Run merge sort Python code
python3 merge_sort.pyYou should see groups of one merge into larger ordered groups.
Try a merge sort Python example
python3 merge_sort.py 5 3 8 1You 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].
python3 arcade.py --race 10000You 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 and quick sort's pivot partitions. The Dev explainers topic has the series.
Send this to the friend asking why merge sort needs extra memory.
Keep this guide
Filed under Dev explainers
Questions about this guide
How do I run merge sort Python code?
Run python3 merge_sort.py from the ALGO ARCADE folder.
How does the merge sort algorithm use an extra row?
It writes the smaller front value from two ordered groups into a second row while merging.
Sources
- ALGO ARCADE READMEgithub.com
- ALGO ARCADE merge sort sourcegithub.com