Scholars Gate
Find a TutorOnline Tutoring
GuidesHow It WorksBecome a Tutor
Log inGet Started
All guides
Computer ScienceGCSE 9 min read

Sorting Algorithms, Visualised

Press play and watch the bars sort themselves — bubble, insertion, selection and merge — with live comparison and swap counters. See why some algorithms are far faster than others.

The ScholarsGate Computer Science Team·Updated 08 Jul 2026

On this page

  • What sorting algorithms do
  • See it: watch them sort
  • Bubble vs insertion vs merge
  • Counting the work
  • Common mistakes
  • Practice
  • FAQ

“Put this list in order” sounds trivial — until you have to spell out exactly how. That is what a sorting algorithm does, and the different ways of doing it reveal, in miniature, the whole art of thinking about efficiency.

What sorting algorithms do

A sorting algorithm takes a list of items — numbers, names, records — and rearranges them into order. There are many ways to reach the same sorted result, so we need a fair way to compare them. Almost every one boils down to two basic operations: comparisons (is this item bigger than that one?) and swaps or writes (move an item to a new position).

Counting comparisons and swaps — rather than timing the code on one particular computer — lets us judge an algorithm independently of the machine it runs on. It is the honest measure of how hard the algorithm is working.

The best algorithm is not the one that finishes first on your laptop — it is the one that does the least work as the list grows.

See it: watch them sort

Reading pseudocode for a sort is one thing; seeing it move is another. In the visualiser below, each bar is a number and its height is its value. Pick an algorithm, press play, and watch the comparison and swap counters climb as the bars settle into order.

Try the same list with each algorithm and compare the final counts — the differences are the whole story.

InteractiveSorting algorithm visualiser
Loading interactive…
Pick an algorithm and press play. Highlighted bars are being compared; gold bars have just been written.
Text description ↓Hide text description ↑

An animated bar chart that sorts itself. You choose bubble, insertion, selection or merge sort and press play; the bars rearrange step by step while live counters show the number of comparisons and swaps. Bubble and insertion repeatedly swap adjacent out-of-order bars; merge sort splits the list and rebuilds it in order.

Bubble vs insertion vs merge

The four classic algorithms reach the same destination by very different routes.

Bubble sortwalks along the list comparing each adjacent pair and swapping any that are out of order. After one full pass the largest value has “bubbled” to the end; it repeats, one fewer element each time, until a pass makes no swaps at all.

Insertion sortgrows a sorted section at the front of the list. It takes the next unsorted item and slides it back into its correct place among the already-sorted ones — much like arranging a hand of playing cards.

Selection sortrepeatedly scans the unsorted part to find the smallest remaining item and places it at the front of that part. It does very few swaps — one per pass — but many comparisons.

Merge sorttakes a divide-and-conquer approach: split the list in half, split each half again, and keep going until every piece is a single item (which is trivially “sorted”). Then it repeatedly merges pairs of sorted pieces back together in order, until the whole list is rebuilt.

Counting the work

Run each algorithm on a longer and longer list and the counters tell a stark story. Bubble, insertion and selection sortall do roughly n × n work on a list of n items — they are O(n²). Double the list and they do about four times the work. Merge sort is far gentler at O(n log n): doubling the list barely more than doubles the work.

Why O(n log n) beats O(n²)

For a list of 1,000 items, an O(n²) sort does on the order of 1,000,000 operations, while an O(n log n) sort does about 10,000 — a hundredfold gap that only widens as the list grows. That is why real software libraries use merge sort (or its relatives), never bubble sort. This scaling is the subject of Big-O notation.

Common mistakes

Thinking bubble sort is a good general-purpose choice

Bubble sort is a teaching tool: it is easy to understand and easy to trace by hand. But its O(n²) cost makes it one of the slowest options at scale, and it is essentially never used in real systems. Knowing how it works is useful; reaching for it in practice is not.

Confusing one pass with one comparison

A single pass through the list contains manycomparisons — up to n − 1 of them. Exam questions often ask for the state of the list “after the first pass”, meaning after a complete sweep, not after a single comparison. Read carefully which the question wants.

Practice

Your turn

You need to sort a list that is already almost in order— only a couple of items are out of place. Which does fewer swaps: insertion sort or selection sort?

Show the answer ↓Hide the answer ↑

Insertion sort.On nearly-sorted data most items are already in place, so each one slots in with barely any movement — very few swaps. Selection sort ignores any existing order and scans the whole remaining list on every pass regardless, so it does no less work just because the list started tidy.

Where next?

The O(n²) and O(n log n) labels above are Big-O notation — the standard language for how an algorithm’s cost grows with the size of its input. It is the natural next step once these sorts make sense.

Key takeaways
  • Sorting algorithms rearrange a list into order; we compare them by counting comparisons and swaps, not wall-clock time.
  • Bubble, insertion and selection sort each reach the answer differently but all cost O(n²).
  • Merge sort splits the list and merges sorted halves, achieving a much faster O(n log n).
  • Insertion sort shines on nearly-sorted data; selection sort does the fewest swaps but the most comparisons.
  • Bubble sort is a teaching tool, not a practical choice at scale — and one pass is many comparisons, not one.

Frequently asked questions

How does bubble sort work?+
Bubble sort repeatedly steps through the list, comparing each adjacent pair and swapping them if they are in the wrong order. After each full pass the largest remaining value has “bubbled” to its correct position at the end. It keeps passing until no swaps are needed.
Which sorting algorithm is fastest?+
For large lists, merge sort is much faster: it runs in O(n log n) time, while bubble, insertion and selection sort run in O(n²). On small or nearly-sorted lists, insertion sort can actually be quickest because of its low overhead.
What is the difference between bubble and insertion sort?+
Bubble sort repeatedly swaps adjacent out-of-order pairs across the whole list. Insertion sort instead builds a sorted section at the front, taking each new item and inserting it into its correct place. Insertion sort usually does fewer swaps on partially-sorted data.
Why is merge sort faster than bubble sort?+
Merge sort splits the list in half repeatedly (about log₂ n levels of splitting) and merges the halves in linear time, giving O(n log n). Bubble sort compares every pair, giving O(n²), which grows far more steeply as the list gets longer.
SC

The ScholarsGate Computer Science Team

Oxbridge & Russell Group computer science tutors

Written and reviewed by ScholarsGate tutors who teach GCSE, A-Level and undergraduate computer science. Every explainer is checked against the AQA and OCR specifications.

Keep exploring

GCSE & A-Level Computer Science tutorsBig-O notation & efficiencyAll interactive guides

Want a tutor to walk you through it?

Book a DBS-checked GCSE Computer Science tutor for a 1-on-1 lesson — online or in person.

Find a GCSE Computer Science tutor
Scholars GateTutoring & Learning

ScholarsGate (Scholars Gate) is a premium UK tutoring marketplace connecting ambitious students with expert tutors across every subject, level, and admissions pathway.

hello@scholarsgate.co.uk
+44 7544 736438
Bath, United Kingdom

Platform

  • Find a Tutor
  • Online Tutoring
  • How It Works
  • Become a Tutor
  • Interactive Guides
  • Blog
  • FAQ

Subjects

  • Mathematics & Computing
  • Natural Sciences
  • Humanities
  • Languages
  • All Subjects

Admissions

  • Medicine & UCAT
  • Maths (TMUA, STEP)
  • Law & LNAT
  • Statements & Interviews
  • All Admissions
4.9/5 average tutor rating
All tutors DBS verified
Secure payments via Stripe
500+ expert tutors

© 2026 ScholarsGate Ltd. All rights reserved.

Privacy PolicyTerms of ServiceCookie PolicySafeguarding