Bubble_sort
Bubble_sort
Bubble Sort is a simple sorting algorithm that repeatedly steps through a list,
compares adjacent elements, and swaps them if they’re in the wrong order. It’s
named because smaller/larger elements "bubble" to the top of the list like bubbles
in water.
Example:
Imagine arranging a line of people by height. Bubble Sort works by comparing two
people at a time and swapping them until everyone is in order.
Time Complexity
Visual Example
Real-World Analogy
•O(n²) is impractical: Sorting 10,000 items could take ~100 million operations.
•Modern alternatives: Use built-in sorts (e.g., Python’s sorted(), list.sort()) which
use O(n log n) algorithms like TimSort.
Summary