aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 6.4Bubble and selection sort
Back to Computer Science HL Topics
6.4.35 min read

Bubble and selection sort (Computer Science HL)

IB Computer Science • Unit 6

Exam preparation

Practice the questions examiners actually ask

Our question bank mirrors real IB exam papers. Practice under timed conditions and track your progress across topics.

Start Practicing

Contents

  • Two ways to put a list in order
  • Bubble sort
  • Selection sort
  • Exam-style question
The big idea: Bubble sort compares neighbouring pairs and swaps them when they are the wrong way round, so the largest value moves to the end each pass.

Selection sort finds the smallest value in what is left and swaps it into place, once per position.

Both algorithms on the same six numbers, with running comparison and swap counts. Switch between them.

Interactive diagram

Explore the labelled diagram, charts and maps for this topic in full study mode.

Claim your free topic

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime
1

What one pass does

2

Why the range shrinks

3

The early exit

4

The cost

Practice with real exam questions

Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.

Try Practice FreeYour first topic is free to keep • No credit card required

Bubble sort

  • O(n²) comparisons, O(n²) swaps
  • Best case O(n) — one pass over sorted data with the early exit
  • Very many swaps: it moves data constantly
  • Slightly simpler to write and to trace

Selection sort

  • O(n²) comparisons, but only O(n) swaps
  • No best case — it always does every comparison
  • At most one swap per position, decided after looking
  • Better when moving data is what costs
The distinction that matters: Both do O(n²) comparisons. The difference is the swaps.

Selection sort looks first and moves once. Bubble sort moves as it goes. When writing data is expensive, that difference is the whole argument.
Both use O(1) space: Each sorts in place, needing only a couple of extra variables however large the list.

So in a question about memory, neither has an advantage — the answer is that both are O(1).

How this is tested — you must trace a pass exactly and compare on both comparisons and swaps. It comes up two ways:

Paper 2 — working with code

  • Trace one or more passes of a sort, 4-6 marks
  • State and justify time and space complexity
  • Compare the two for a given data set

Paper 2 — the algorithmic-thinking question

  • Reason about pass counts with no code shown
  • Explain which sort suits a stated situation
The classic trap: Saying selection sort is more efficient. Both do O(n²) comparisons — selection sort only wins on swaps. Saying which measure you mean is the mark.
IB-style questionTrace[6 marks]

Show the list after each pass of a bubble sort on [5, 2, 8, 1], then state the complexity and compare with selection sort.

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Bubble and selection sort. Write your answer and get instant AI feedback — just like a real IB examiner.

the list after one complete pass of a selection sort on [5, 2, 9, 1]. [2 marks]

Related Computer Science HL Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types
6.1.2Substrings
6.1.3Exception handling
6.1.4Debugging
View all Computer Science HL topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science HL

Previous
6.4.2Linear and binary search
Next
Recursion6.4.4

23 questions to test your understanding

Reading is just the start. Students who tested themselves scored 82% on average — try IB-style questions with AI feedback.

Start FreeView All Computer Science HL Topics