Add Merge Sort in OCaml#5991
Conversation
rzuckerm
left a comment
There was a problem hiding this comment.
Sorry, but this does not look like anything that is recognizable as a merge sort. Please add some comments as to what this is doing.
|
Added some comments, hope they make the bottom up merge sort a bit easier to see. I recognize that top down is the more commonly seen variant of merge sort, but at least Wikipedia recognizes both top down and bottom up versions as merge sort. The problem description doesn't specify a version. You'll see that this implementation exactly matches what it states:
I did implement the top-down version as well (see the first commit in the chain), but OCaml's linked lists feel awkward to repeatedly find the midpoint of, and using an array feels less idiomatic. The bottom up allows a simple map to cover the entire splitting part for us, and uses a bottom-up folding pattern instead of the function call stack to coordinate merges. |
I Am Adding a New Code Snippet in an Existing Language
Add {PROJECT} in {LANGUAGE}formatI experimented both with a top-down and bottom-up mergesort, as the problem description does not specify which one should be implemented. I ended up going with the bottom-up approach, it felt like a better fit for OCaml than the top-down one.