The following are examples of computing times in algorithm analysis. To make the difference clearer, let's compare based on the execution time where n = 1,000,000 and time = 1 millisecond:
Big-Oh Description Algorithm Running Time Sample Code Implementation
O(1) Constant return n (n+1)/2
O(log2 n) Logarithmic Binary Search 19.93 microseconds while n > 1 count < count + 1 n = n / 2
O(n) Linear Sequential 1.00 seconds for i = 1 to n search sum < sum + i
O(n log2 n) Heapsort 19.93 seconds
O(n^2) Quadratic Insertion Sort 11.57 days for i = 1 to n for j = 1 to n sum = sum + i
O(n^3) Cubic Floyd's Algorithm
O(2^n) Exponential 317.10 centuries
O(n^n) Eternity
O(log2 log2 n) Operations on the O-Notation: Rule for Sums Suppose that T(n) = O(f(n)) and Tz(n) = O(g(n)): Then, t(n) = Ti(n) + Tz(n) = O(max(f(n), g(n))).