BeginnerAbout 10 min

    Bubble Sort

    Read the full article on Substack

    5 min read.

    The simplest sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. "Bubbling" the largest element to the top.

    Think of it this way: Imagine air bubbles in water. Heavier ones sink, lighter ones float up. In Bubble Sort, the largest element 'bubbles up' to the end of the list in each pass.

    3827433982100123456

    Start: 7 values. Each pass bubbles the largest unsorted value to the right.

    1/52

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    One pass of bubble sort

    Sequence

    Order what happens during a single pass.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    What is the worst-case time complexity of Bubble Sort?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going