Annotated Algorithms: Bubble Sort, Insertion Sort, and Selection Sort

Commonality one: Sorting an array in place

Take a look at the reverseArray function below:

Commonality two: The “swap” helper function

Bubble Sort

Source: https://algorithm-visualizer.org/brute-force/bubble-sort
Source: https://algorithm-visualizer.org/brute-force/bubble-sort
Source: https://algorithm-visualizer.org/brute-force/bubble-sort
Source: https://algorithm-visualizer.org/brute-force/bubble-sort

Insertion Sort

  1. The next number to the left ( j - 1 ) is smaller than the number we’re moving
  2. We’ve reached the end of the array, or index 0

Selection Sort

Coming up…

--

--

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