Courses / Computer Science I
Algorithmics

Complexity Analysis

Computer Science I 234 words Free to read

Measuring Cost Precisely

Complexity analysis predicts how an algorithm's time (operations) and space (memory) grow with input size nn without running code.

The tool is asymptotic notation, which ignores constants and lower-order terms to focus on scaling behavior for large inputs:

NotationBound TypeMeaning
Big-O (OO)Upper boundGrows at most this fast
Big-Omega (Ω\Omega)Lower boundGrows at least this fast
Big-Theta (Θ\Theta)Tight boundGrows exactly this fast

Count dominant operations: a loop is O(n)O(n), nested loops are O(n2)O(n^2), halving is O(logn)O(\log n), and fixed work is O(1)O(1).

Common pitfall: Writing 'O(3n2+5n)O(3n^2 + 5n)'. Drop constants and lower terms: it is simply O(n2)O(n^2), because the dominant term alone captures scale.

One function, sandwiched between two scaled copies of the same curve

Cases and Space

Costs depend heavily on case: the worst case bounds maximum slowness, the average case reflects typical inputs, and the best case is usually uninformative.

Space complexity measures memory. Algorithms often feature a space-time trade-off: merge sort takes O(nlogn)O(n \log n) time but O(n)O(n) extra space, while heapsort sorts in place with O(1)O(1) space.

Quick Rules:

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

10practice questions
2interactive scenes

Algorithmics