Beginner
Time Complexity (Big-O)
How an algorithm's running time grows with input size.
STEP 1 · CONCEPT
Big-O describes the growth rate of work as n gets large, ignoring constants.
STEP 2 · COMMON CLASSES
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ).
STEP 3 · PRACTICE
Count nested loops: two nested loops over n usually means O(n²).
WORKED EXAMPLE
Binary search halves the list each step, so 1,000,000 items need only about 20 comparisons: O(log n).
Formulas
Binary search
T(n) = O(log₂ n)
Merge sort
T(n) = 2T(n/2) + n = O(n log n)
Practice questions
Q1.Time complexity of binary search?
Time Complexity (Big-O) · Easy
Q2.Worst case of quicksort?
Time Complexity (Big-O) · Medium
Q3.Accessing an array element by index is…
Time Complexity (Big-O) · Easy