Bubble Sort
Let’s learn about the bubble sort in detail.
We'll cover the following
Introduction
Bubble sort is the slowest sorting algorithm. However, when the data is small, it is simple to implement and use.
How bubble sort works
In bubble sort, we compare each pair of adjacent values. We want to sort values in increasing order, so if the second value is less than the first value, we swap these two values. Otherwise, we go to the next pair. This way, the largest values bubble to the end of the array.
The greatest value will be at the rightmost position after the first pass. We’ll go over the array n times to completely sort it. Let’s look at an illustration of the first pass of bubble sort on an unsorted list.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.