Hacker News new | past | comments | ask | show | jobs | submit login
Intuitive Guide to Merge Sort (photonlines.substack.com)
34 points by photon_lines on Nov 30, 2023 | hide | past | favorite | 2 comments



People should learn bottom-up mergesort. It's not recursive, so it's easier to understand. Do multiple passes through the array, merging adjacent sub-lists:

First pass: merge every two neighboring single values into length-2 lists.

Second pass: merge every two neighboring length-2 lists into length-4 lists.

Third pass:merge every two neighboring length-4 lists into length-8 lists.

After log(n) passes, you're done!

This is probably what the magnetic tape drives were busy doing in those 1970s action movies, where the hero breaks into the computer room and fights the villains: they were driven by fortran programs, which didn't support recursion.


Label your axes.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: