Search⌘ K
AI Features

Big-O Notation

Explore the concept of Big-O notation to understand how running times of algorithms are compared based on their growth rates. Learn to interpret the definition, inequalities, and examples that highlight how functions scale and what it means for an algorithm's efficiency in terms of input size.

Given any two functions f(n)f(n) and g(n)g(n), when we say a function f(n)f(n) is O(g(n))O(g(n)), we are expressing a certain relationship between the two functions.

Let’s look at the definition, but don’t worry if you don’t grasp it immediately. We’ll expand on its meaning and usage bit by bit.

Definition

We say f(n)f(n) is O(g(n))O(g(n)) if for some positive constants cc' and nn',

0f(n)c g(n)      for all nn0 \leq f(n) \leq c' \ g(n) \ \ \ \ \ \text{ for all } n \geq n'

There are two inequalities above. Let’s take the one on the right first and see what it means.

The inequality on the right

First, let’s focus on the following part of the definition

f(n)c g(n)      for all nnf(n) \leq c' \ g(n) \ \ \ \ \ \text{ for all } n \geq n'

for some positive constants cc' ...