Algorithms
⏱ ~3-min readAceMark GuideWhat this topic is really about
Quicksort’s worst case occurs when the pivot divides the array into extremely unbalanced partitions, such as a sorted or reverse‑sorted list, leading to recursive calls of size n‑1 and n‑2; the total work sums to a quadratic series, giving O(n²) time. The choice O(n log n) describes the average case, not the worst case, so it is a common misconception.
This recurrence falls under Case 2 of the Master Theorem, where the driving function f(n) matches the algorithmic work, resulting in an extra logarithmic factor. Option A is incorrect because it fails to account for this log n factor when the two terms are asymptotically equal.
See the mechanism
Binary search repeatedly divides the search interval in half, leading to a logarithmic time complexity of O(log n). A diagram for this topic isn't available yet — the worked example below walks the same reasoning step by step.
An exam-style question, fully explained
The time complexity of binary search on a sorted array of n elements is:
- Identify what the question tests: The time complexity of binary search on a sorted array of n elements is:.
- Binary search repeatedly divides the search interval in half, leading to a logarithmic time complexity of O(log n).
- Linear time, or O(n) (Option A), is incorrect because it describes a sequential search where every element is checked one by one.
Traps the examiner sets
- Linear time, or O(n) (Option A), is incorrect because it describes a sequential search where every element is checked one by one.
- The choice O(n log n) describes the average case, not the worst case, so it is a common misconception.
- Option A is incorrect because it fails to account for this log n factor when the two terms are asymptotically equal.
Test your recall
Answer each from memory — you'll see instantly whether you're right and why.
Run a focused 10-question mini-mock on Algorithms and see it stick.
Practice more of this topic →