Exit Slides

Bubble Sort

overview

Summary

bubble_sort is a simple comparison algorithm. It repeatedly scans a list, compares adjacent items, and swaps if out of order. Larger values bubble to the end each pass. Use an outer_loop for passes and an inner_loop over adjacent_pairs. Track a swap_flag to stop early when no swaps occur. Worst and average time_complexity: O(n^2). Best case: O(n). space_complexity: O(1). It is stable_sort and in_place. Suited for small lists and teaching.
← Prev Topic Slide 1 / 2 Next Topic: Insertion Sort →