13 Feb 2021

Algorithms, Volume 1, Sorting

Sorting Algorithms

Often times while programming in general, the programmer eventually arrives upon a list that they want sorted.

Why and how? Well apart from the fact that they seem to be one of the top "whiteboard" problems that all the shiny tech companies seem to prefer, they do come in quite handy in real world code.


I had a list of "holdings" I needed to sell in the following format:

id symbol price
8 TESLA 1612
9 MSFT 500
11 GEPIL 1004

(indicative data, not to scale)

For reasons I will not go into here, I wanted the least expensive ones to be sold off first.

The list:

[1700, 1612, 500, 85, 1004, ]

needed to be sorted in ascending order, like so:

[85, 500, 1004, 1612, 1700, ]

Let's take a look at the different approaches one can follow to arrive at this final list.

Click here to go to the next post where we discuss Bubble sort.