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

Programming algorithms

Practice Flashcards

Flip cards to reveal answers
Card 1 of 256.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 25 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.

6.4.45 cards

Card 16definition
Question

What are the two parts of a recursive function?

Answer

A **base case** that returns without recursing, and a **recursive case** that calls itself on a smaller problem.

Card 17concept
Question

Why does deep recursion cause a stack overflow?

Answer

Each call keeps a **stack frame** — parameters, locals, return address — and none is released until the base case is reached.

Card 18concept
Question

Why do recursive calls need a stack?

Answer

They return in the **reverse order** they were made, most recent first — last in, first out.

Card 19comparison
Question

When is recursion genuinely better than iteration?

Answer

When the **data is self-similar** — a tree, a folder structure, a nested expression. Iterating those needs an explicit stack managed by hand.

Card 20concept
Question

Is recursive factorial a good choice?

Answer

It is a good **teaching example**, not a good choice — a loop is faster and uses constant memory.

6.4.55 cards

Card 21process
Question

What are the two halves of a recursive trace?

Answer

**Down** — each call is made and waits, with no arithmetic. **Up** — each returns a value, and the arithmetic happens.

Card 22concept
Question

When does the arithmetic in n + recurse(n-1) happen?

Answer

On the way **up**, once the base case has returned a value to add to. Nothing is computed descending.

Card 23process
Question

How should a recursive trace be laid out?

Answer

Indent each call **one level further** than its caller; leave the return blank going down and fill it in coming back up.

Card 24concept
Question

What changes with two recursive calls per level?

Answer

The calls form a **tree**, the left branch completes before the right, and the same values are computed repeatedly.

Card 25concept
Question

Why is naive Fibonacci slow?

Answer

Calls grow **exponentially** — fib(30) makes over 1.3 million — because nothing is remembered between branches and sub-results are recomputed.

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 HL Topic 6.4 Flashcards | Programming algorithms | Aimnova