4.2.1.1 Bubble Sort, Selection Sort, Insertion Sort

These are some of the simpler ways to sort things:

  • Bubble Sort: Think of bubbles rising in water. In Bubble Sort, you go through a list, compare two items next to each other, and if they're in the wrong order, you swap them. You keep doing this over and over, and the largest (or smallest) items "bubble up" to their correct place in the list. It's a bit like sorting cards by repeatedly swapping any two adjacent cards that are out of order.
  • Selection Sort: Imagine you have a bunch of unsorted papers. With Selection Sort, you look through all the papers to find the very smallest one. You pick it out and put it at the beginning of your sorted pile. Then, you look through the remaining papers, find the next smallest, and put it next in your sorted pile. You keep "selecting" the next smallest item until all papers are sorted.
  • Insertion Sort: This is like how you might sort a hand of playing cards. You start with one card (which is already "sorted"). Then, you take the next card from your unsorted pile and "insert" it into the correct spot among the cards you've already sorted. You repeat this for every card until your whole hand is sorted.