---
title: "Quadratic Sorts: Bubble and Insertion"
description: "Two sorting methods that work by comparing neighbouring values, one bubbling the largest to the end each pass and one placing each value into an already sorted front. Both do work proportional to n sq"
canonical: https://lightmysky.com/learn/computing/quadratic-sorts-bubble-and-insertion-mt_cBUIBa15jQ
source: https://lightmysky.com/learn/computing/quadratic-sorts-bubble-and-insertion-mt_cBUIBa15jQ.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Quadratic Sorts: Bubble and Insertion

Two sorting methods that work by comparing neighbouring values, one bubbling the largest to the end each pass and one placing each value into an already sorted front. Both do work proportional to n squared, which is where big-O first bites.

Subject: Computing · Area: Algorithms & Data Structures · Ages 16 to 17
Page: https://lightmysky.com/learn/computing/quadratic-sorts-bubble-and-insertion-mt_cBUIBa15jQ

## Ready when they can

- Trace one full pass of bubble sort and one insertion step on the same six values
- Count the comparisons each method makes and match the count to O(n squared)
- Say when insertion sort beats bubble sort, and what nearly sorted input does to each

## Lesson: Two slow sorts that teach a lot

Bubble sort works by comparing neighbouring values. One pass walks along the list swapping any pair that sits out of order, so the largest value bubbles to the end. Repeat passes until no swaps are needed, and the list stands sorted.

Insertion sort builds the sorted part from left to right. Each step takes the next value and slides it into its correct slot among the values already sorted, shifting bigger ones along. Picture a card player slotting each dealt card into a sorted hand.

**Example.** Trace both on the same six values in the worst case. Insertion compares the newcomer against all placed cards: 5 + 4 + 3 + 2 + 1 makes 15 comparisons. Bubble does a similar total. Both methods are O(n squared) because their comparison counts grow with the square of n: each of n items can meet n others, so doubling the list roughly quadruples the work.

**Tip.** Insertion beats bubble on nearly sorted input, where each value slots in almost at once and the method runs in nearly linear time. Bubble can only quit early with an early exit flag that stops it after a pass with no swaps; without that check it still grinds through all passes. When asked which is faster, always name the input shape first.

**Recap.** Trace one pass, count the comparisons, feel the square.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Traversing a List to Build a Result](https://lightmysky.com/learn/computing/traversing-a-list-to-build-a-result-mt_lusbjHFt95)
- [Big-O Notation and Orders of Growth](https://lightmysky.com/learn/computing/big-o-notation-and-orders-of-growth-mt_mkqgxhJ509)

## Opens up

- [Loop Invariants and Proving an Algorithm Correct](https://lightmysky.com/learn/computing/loop-invariants-and-proving-an-algorithm-correct-mt_fWnstju2ns)
- [Merge Sort and Divide and Conquer](https://lightmysky.com/learn/computing/merge-sort-and-divide-and-conquer-mt_OAutL4c7_l)
