Practice question · Put in order
Order these complexity classes from slowest-growing to fastest-growing.
- O(n^2)
- O(log n)
- O(n log n)
- O(1)
- O(n)
Hints
- Constant grows slowest; a squared term grows fastest here.
- Logarithmic beats linear, which beats linearithmic, which beats quadratic.
Show the answer
- O(1)
- O(log n)
- O(n)
- O(n log n)
- O(n^2)
Why
From slowest to fastest growth: O(1), O(log n), O(n), O(n log n), O(n^2). Knowing this ordering is what lets you compare algorithms at a glance.
Practise Complexity Analysis
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.