Sort like a Boss!

4 elementary sorting algorithms

These are the 4 elementary sorting methods everyone must know.

No code? No problem. We will keep it visual.

Image for post
Image for post
“Bubble” up the cards slowly into their proper position.

Step 1: Moving from left two right, pick two cards at a time.

Step 2: Swap them if they are out of order.

Step 3: Do many passes until all cards are sorted.

Practice bubble sort at the dojo.

Image for post
Image for post
“Insert” cards one at a time into their proper position.

Step 1: Moving from left to right, pick each card.

Step 2: Move it to its proper position among others to its left.

Step 3: And so on, until you reach the end.

Practice insertion sort at the dojo.

Image for post
Image for post
“Select” the next best card, move it into its proper position, rinse and repeat.

Step 1: Moving from left to right, pick each card.

Step 2: Then pick the best card from all the cards to its right.

Step 3: If second pick is better than the first pick, exchange.

Step 4: And so on, until you reach the end.

Practice selection sort at the dojo.

Image for post
Image for post
Divide and conquer like a 👑 boss

Step 1: Divide your cards into two sets.

Step 2: Sort each set separately.

Step 3: Merge them back in order.

Practice merge sort at the dojo.

It depends.

  • Firstly, never use Bubble sort, as it is the slowest.
  • Use Selection or Insertion sorts for small data sets.
  • Use Merge (and other types) of sorts for larger data sets.

Written by

Tech

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store