Insertion Sort

Data Structures & Algorithms, Sorting

Josephine Gyamera

--

Insertion sort operates much like arranging a hand of cards for a game of poker. You probably would want to rearrange the cards in some order before playing. In most cases, the order is ascending. With this assumption, let’s walk through how we will rearrange the unsorted cards [8, 3, 7, 1, 4, 6].

  1. Beginning with the first card, 8, we compare it with the next card, 3. Since 3 is smaller, we switch their positions, resulting in [3, 8, 7, 1, 4, 6].
  2. Next, we check 8, we find it’s larger than…

--

--