Bubble Sort - Algrithm and Data Structure
Bubble Sort - Algrithm and Data Structure
1. Starting from the first index, compare the first and the second elements.
2. If the first element is greater than the second element, they are swapped.
3. Now, compare the second and the third elements. Swap them if they are not in
order.
4. The above process goes on until the last element
Compare the Adjacent Elements
2. Remaining Iteration
The same process goes on
for the remaining iterations.
To solve this, we can introduce an extra variable swapped. The value of swapped is
set true if there occurs swapping of elements. Otherwise, it is set false.
After an iteration, if there is no swapping, the value of swapped will be false. This
means elements are already sorted and there is no need to perform further
iterations.
Optimized Bubble Sort Algorithm
Optimized Bubble
Sort in Python
Bubble Sort Complexity
Bubble Sort Applications
● complexity does not matter
● short and simple code is preferred
● Before perform other algorithms
References
● Python.org
● The Python Book
● w3school.com
● programiz.com
Thank You