Back to Topic 6.4 — Programming algorithms
6.4.3Computer Science SL5 flashcards

Bubble and selection sort

Practice Flashcards

Flip to reveal answers
Card 1 of 56.4.3
6.4.3
Question

How does bubble sort work?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All 5 Flashcards — Bubble and selection sort

Sign up free to track progress and get spaced-repetition review schedules.

Card 1process

Question

How does bubble sort work?

Answer

It compares each neighbouring pair and swaps any that are out of order. Each pass sends the largest remaining value to the end, so the next pass can compare one fewer pair.

Card 2process

Question

How does selection sort work?

Answer

For each position it looks through the whole remaining list, remembering where the smallest value is, then swaps it into place. At most one swap per position.

Card 3comparison

Question

How do the two sorts compare on efficiency?

Answer

Both make O(n²) comparisons. Bubble sort makes up to O(n²) swaps; selection sort makes only O(n). Bubble sort has a best case of O(n) on sorted data thanks to its early exit, while selection sort has none.

Card 4concept

Question

What is the space complexity of bubble and selection sort?

Answer

Both are O(1). Each sorts in place, needing only a couple of extra variables however large the list becomes.

Card 5concept

Question

When is selection sort the better choice?

Answer

When writing data is far more expensive than reading it. The comparison counts are identical, so the algorithm doing O(n) swaps instead of O(n²) is clearly better.

Track your progress with spaced repetition

Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.

Start Free
IB Computer Science Bubble and selection sort Flashcards | 6.4.3 | Aimnova