2. Algorithm Analysis

Once an algorithm is shown to be correct, consider the:

Complexity

The time taken will depend on the instance of the problem being solved.

RAM Model of Computation

Abstract random access machine

Formal Definitions

Big O (upper bound)

O(G)=fc>0:x0:xx0:0f(x)cg(x) O(G) = {f|\exists c>0: \exists x_0: \forall x\ge x_0: 0 \le f(x) \le c \cdot g(x)}

That is, f(x)f(x) is part of the set O(g)O(g) if there exists a positive multiplier cc such that for every value of xx greater than x0x_0, f(x)cg(x)f(x) \le c\cdot g(x).

Big Omega (lower bound)

Ω(G)=fc>0:x0:xx0:0c cdotg(x)f(x) \Omega(G) = {f \exists c>0: \exists x_0: \forall x\ge x_0: 0 \le c\ cdot g(x) \le f(x)}

That is, f(x)f(x) is part of the set Ω(g)\Omega(g) if there exists a positive multiplier cc such that for every value of xx greater than x0x_0, cg(x)f(x)c\cdot g(x) \le f(x).

Big Theta (tight bound)

Ω(g)=O(g)Ω(g) \Omega(g) = O(g) \cap \Omega(g)

That is, f(x)f(x) is part of the set Θ(g)\Theta(g) if it is such that for every value of xx above x0x_0, there exists c1c_1 and c2c_2 such that that c1g(x)f(x)c2g(x)c_1 \cdot g(x) \le f(x) \le c_2 \cdot g(x).

The worst case and best case are functions: the algorithm is not, so we cannot define the algorithm by Big O/Omega/Theta notation.

The best case of an algorithm will be Θ(g)\Theta(g); the algorithm is not Θ(g)\Theta(g). Ideally, an algorithm would be separately categorized by its best and worst case. In practice, we often categorize the algorithm by its worst case.

Common functions, sorted by complexity descending:

Functions
x!x!
axa^x
xax^a
xlog(x)x \log(x)
xx
log(x)\log(x)
aa