Python DSALesson 105Free preview
Bubble Sort
This lesson is part of Python · All levels
Summary
This lesson discusses Bubble Sort, the simplest sequencing algorithm that works by comparing a pair of adjacent elements and swapping them out when the order is wrong. This process is repeated until there is no more exchange, so the largest element bubbles into the rightmost position. Because of its complexity, bubble sort is commonly used for learning and small-sized data.
Key points
- Each pass compares adjacent elements and exchanges them if the left element is larger.
- After one pass, the largest element is in the rightmost position and is not pushed back.
- Repetition stops early when no exchange occurs in one pass.
- The best complexity for the sorted data and the worst complexity for the reverse data.
- Bubble sort is stable because the same elements never change positions.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.