Knuth's merge-sort in C. Definitely in the style of mathematician programming.
Knuth's merge-sort in C. Definitely in the style of mathematician programming.
I'm starting to appreciate how useful it is to revisit old code that you wrote and learn from it.
I had previously implemented mergesort in obj-C a few years ago, and looking back at it now, it really hasn't held up to the test of time.
It was correct, but I allocated a ton of unnecessary structures, which is bad when you have recursion and you have a large amount of input data.
Also looking at it now that a few years have gone by, I find that it could be more legible.
This implementation is in C++ and instead of creating data structures willy nilly, I modify the input array in place.
There is a temporary array being created during the merge operation, but I can't get rid of that one.
This version is way cleaner and easier to read.
https://github.com/aeu/legible-algorithms/tree/master/sorting/improved-mergesort
βοΈ Day 8/100: #Leetcode daily question
π¨ Question: 179. Largest Number
Today's question was good and can be answered using a custom sorting function. I did this with 3 approaches:
1. Built-in sort (provided custom key fn).
2. #quicksort
3. #MergeSort
πββ¬ Check out my #GitHub where I post all the daily streak π₯ questions and #LeetcodeContest π solutions
π Solution Link: https://github.com/akshatsingh1718/leetcode/tree/main/largestNumber
π My Leetcode Github: https://github.com/akshatsingh1718/leetcode
Kuthβs Merge Sort in C
Taken from Knuth Algorithm S mergesort P162-163 Vol 3 Second edition 1998
The major change is that the scratch buffer is not required to be adjacent and there are some changes because C array indexing usually starts with 0. This is very much how a mathematician write code. You have to remember a larger than usual single letter variables and it has a very clever clockwork
https://www.yodaiken.com/2024/01/24/kuths-merge-sort-in-c/
#theory #clang #Knuth #mergesort
OkΓ© vandaag een #ode aan #mergesort, een supersimpele manier van sorteren. #algoritme #simpel #effectief #schoonheid van #eenvoud
* deel je lijst in twee delen. Herhaal voor elk deel tot het 1 of 2 groot is
* voeg de delen samen, waarbij steeds de eerste elementen van de delen vergelijkt. De kleinste mag voorop. Herhaal tot alle delen weer zijn samengevoegd
Supermakkelijk om het werk te verdelen over meedere verdelers en samenvoegers, waardoor dit ook parallel en sneller is uit te voeren.
What are the different types of merge sort used for?
https://stackoverflow.com/questions/37341369/what-are-the-different-types-of-merge-sort-used-for
γγγιγγ¨γγγγ¨γγ§γͺγγγ