Algorithm Efficiency Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Algorithm Efficiency.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
The ratio of useful output energy (or power) to total input energy, expressed as a percentage β always less than 100% due to energy losses.
Does doubling the data double the time? Or quadruple it? Or barely change it?
Read the full concept explanation βHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Algorithm efficiency matters increasingly as data growsβa slow algorithm on small data may fail completely on large data.
Common stuck point: Big O ignores constant factorsβ2n and 100n are both O(n) because the growth rate is what matters.
Sense of Study hint: When analyzing efficiency, first identify the input size n. Then count how many times the most-repeated operation executes as a function of n (look for nested loops). Finally, express the growth rate using Big O, dropping constants and lower-order terms.
Worked Examples
Example 1
hardSolution
- 1 Step 1: Algorithm A: when size doubles (10β20), steps quadruple (100β400). This suggests O(n^2).
- 2 Step 2: Algorithm B: when size doubles, steps double (10β20). This suggests O(n).
- 3 Step 3: Algorithm B is more efficient β it grows linearly while A grows quadratically.
Answer
Example 2
hardPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
hardExample 2
hardRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.