August 2024
Intermediate to advanced
516 pages
11h 47m
English
The Bubble Sort algorithm contains two significant kinds of steps:
Comparisons: Two numbers are compared with one another to determine which is greater.
Swaps: Two numbers are swapped with one another to sort them.
Let’s start by determining how many comparisons take place in Bubble Sort.
Our example array has five elements. Looking back, you can see that in our first pass-through, we had to make four comparisons between sets of two numbers.
In our second pass-through, we only had to make three comparisons. This is because we didn’t have to compare the final two numbers, since we knew that the final number was in the correct spot due to the first pass-through.
In our third pass-through, we made two comparisons, ...
Read now
Unlock full access