Back to all Computer Science topics
Topic 6.4Computer Science SL15 flashcards

Programming algorithms

Practice Flashcards

Flip cards to reveal answers
Card 1 of 156.4.1
6.4.1
Question

What does Big O describe?

Click to reveal answer

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

All Flashcards in Topic 6.4

Below are all 15 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.

6.4.15 cards

Card 1definition
Question

What does Big O describe?

Answer

How an algorithm's work grows as the data grows — the shape of the growth, not the time in seconds, which depends on the machine it runs on.

Card 2process
Question

How do you work out an algorithm's complexity?

Answer

Count the loops over the data. No loop is O(1), one loop is O(n), a loop inside a loop is O(n²), and halving what is left at each step is O(log n).

Card 3concept
Question

Why is 2n + 5 written as O(n)?

Answer

Big O describes the shape of the growth, and constants and lower-order terms do not change that shape. Doubling the data still doubles the work.

Card 4comparison
Question

What is the difference between time and space complexity?

Answer

Time complexity is how the number of steps grows; space complexity is how the extra memory grows, not counting the input. Bubble sort is O(n²) time but O(1) space, because it sorts in place.

Card 5concept
Question

What does O(n²) mean in practice?

Answer

Twice the data means four times the work, and ten times the data means a hundred times. At 1,000 items that is a million steps; at 10,000 it is a hundred million.

6.4.25 cards

Card 6process
Question

How does linear search work, and what does it cost?

Answer

It checks each item in turn until it finds the target or runs out, returning the position or -1. Best case O(1) if the target is first, worst case O(n) if it is last or absent.

Card 7process
Question

How does binary search work?

Answer

Look at the middle item. If it equals the target, stop. If it is too small the target is to the right, so move low to mid + 1; if too big, move high to mid - 1. Each step discards about half the remaining list.

Card 8concept
Question

Why must binary search have sorted data?

Answer

Discarding half depends on knowing which half the target would be in, which only holds if the list is in order. On unsorted data it does not run slowly — it returns the wrong answer.

Card 9concept
Question

How does binary search terminate?

Answer

When low passes high, meaning there is nothing left to search. It then returns -1 to indicate the target is absent.

Card 10comparison
Question

How do the two searches grow with the data?

Answer

Doubling the list doubles linear search's worst case, but adds only one comparison to binary search's. Sixteen items need at most four binary comparisons; a million need about twenty.

6.4.35 cards

Card 11process
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 12process
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 13comparison
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 14concept
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 15concept
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.

Want smart review reminders?

Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.

Start Free
IB Computer Science SL Topic 6.4 Flashcards | Programming algorithms | Aimnova