> For the complete documentation index, see [llms.txt](https://tanias-workspace.gitbook.io/tanias-little-corner/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tanias-workspace.gitbook.io/tanias-little-corner/algorithms/bubble-sort.md).

# Bubble Sort

Bubble Sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This process is repeated until the list is sorted.

**Steps**:

1. Start from the beginning of the array.
2. Compare each pair of adjacent items.
3. Swap them if they are in the wrong order.
4. Repeat the process for the entire array, reducing the comparison length each time

<figure><img src="/files/U2aVFZJVYIRbWARHmg0y" alt=""><figcaption></figcaption></figure>

## &#x20;Implementation in C++

<figure><img src="/files/3jv16PWd6KnRyCXfjqGb" alt=""><figcaption></figcaption></figure>

**Bubble Sort**: Simple but inefficient for large lists. Time complexity: O(n^2).
