Today, I focused on sorting algorithms! I don’t like spending too much time on these, because any language you use will have sorting methods in its standard library; but the tradeoffs between the popular algorithms are laden with gems of foundational CS knowledge.
Mergesort is a fancy-shmancy recursive algorithm that goes something like this:
* Given an array, if it has a single element, return it. Otherwise:
* Divide the array roughly in half, then Mergesort it.
* Merge the two sorted arrays.
I chose to implement Mergesort because it has some concepts that are intrinsic to other common algorithms. For instance, “merge two sorted linked lists” is a common interview question.
You can see my Swift implementation of Mergesort in today’s images. One of the MANY things I love about Swift is the ability to use extensions like this. It’s just so elegant 💁🏼♀️
One important note about Mergesort is that, while its runtime complexity is quite optimal at O(n log n), its space complexity is O(n). Therefore, it is not suitable for arrays that are very large. On the other hand, Mergesort is the sorting algorithm of choice for functional languages like Haskell. Something like Quicksort mutates an array in place, but Mergesort creates a new array; this is ideal for languages that already copy value objects anyway. Plus, unlike Quicksort and Heapsort, it’s stable! 🤙🏼
With its enhanced design, the latest technology, exhilarating performance and advanced preventative safety features, this is the revolution of an icon that has already sold over five million units worldwide. 🚗💨
This page is not the same anymore, I do not try so hard to keep going forward, I'm sorry :(
Does anyone want to help me continue with this page? Or someone wants this page?.
Send me a message and we will clarify this better <3 #taylorswift#taylor#swift#swiftie#page#instagram @taylorswift