Bubble sort
Bubble sort is an algorithm that we'll learn simply for practice because it's too simple and basic for any real-world use (and incredibly slow). At its core, bubble sort starts from the leftmost value and keeps moving to the right. When moving from left to right, if the next value being compared is greater than the previous one, then it's replaced by a higher value and the sorting continues. In other words, it takes the largest element and bubbles it to the top, and this is why it's called bubble sort. Bubble sort requires many iterations to sort through a typical list since it analyzes one value at a time and finds its right position in the list. In an array of 97 elements, bubble sort would iterate 97 times before it sorts all ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access