Practice Bubble Sort in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

A simple sorting algorithm that repeatedly walks through the list, compares each pair of adjacent elements, and swaps them if they are in the wrong order. This process repeats until no more swaps are needed, meaning the list is fully sorted.

Heavier bubbles sink and lighter bubbles rise โ€” larger values slowly move to the end of the list.

Showing a random 20 of 50 problems.

Example 1

medium
Bubble sort [1,3,2,4][1, 3, 2, 4] ascending with early-exit. Passes and swaps?

Example 2

medium
Fully bubble sort [4,2,3,1][4, 2, 3, 1] ascending. Give the list after each pass and the total swaps.

Example 3

easy
If a bubble sort pass makes zero swaps, what does that tell you?

Example 4

hard
A list of 11 million records takes ~1s with merge sort. Roughly how long with bubble sort, assuming same per-op cost?

Example 5

easy
After kk passes, why can you skip comparing the last kk elements?

Example 6

challenge
Prove that bubble sort's worst-case swap count is exactly n(nโˆ’1)/2n(n-1)/2.

Example 7

easy
True or false: bubble sort is a STABLE sorting algorithm.

Example 8

medium
How many comparisons does unoptimized bubble sort do on a list of 55 (sum over all passes)?

Example 9

hard
Why does bubble-sort swap count equal the inversion count of the input?

Example 10

easy
Do one pass of ascending bubble sort on [5,2,4][5, 2, 4].

Example 11

easy
Bubble sort compares which elements?

Example 12

easy
On a list of 66 elements, how many adjacent comparisons does the first pass make?

Example 13

hard
On a list where every element is one position away from its sorted spot, how many swaps does bubble sort make?

Example 14

easy
On a list of 77, how many adjacent comparisons does the FIRST pass make?

Example 15

medium
Fully bubble sort [2,4,1][2, 4, 1] (ascending). Give the final list and total number of swaps.

Example 16

easy
How does bubble sort decide whether to swap two adjacent elements?

Example 17

easy
Do one pass of ascending bubble sort on [3,1,2][3, 1, 2].

Example 18

medium
Why might bubble sort still be taught despite being slow?

Example 19

easy
After one full pass of ascending bubble sort, which element reaches its correct final position?

Example 20

medium
An array [2,2,1][2, 2, 1] is sorted with bubble sort. After sorting, do the two 2's keep their original relative order? Why or why not?