Lecture 006

Big-O Notation

Timing

/usr/bin/time -p /.a.out -r 200 -n 100000
real x.xx
user x.xx (look at this)
sys  x.xx

Wall-clock time:

Counting Steps

Counting Steps

Counting Steps
Method: We count steps according the worst case. Problem:

We don't know the constants

We don't know the constants

Comparing Algorithms by Counting Steps

F(x) function has f(n) complexity G(x) function has g(n) complexity

Bad Definition: F(x) is better than G(x) if for all n, f(n)<=g(n) - well, some function can better handling small inputs. We need some algorithms that can do well in stress test.

Better Definition: F(x) is better than G(x) if there exists a natural number n0 such that for all n>n0, f(n)<=g(n)

Good Definition: there exists a natural number n0 and a real c>0 such that for all n>=n0, f(n)<=cg(n) (O(g(n)) is a set of functions where f(n) \in O(g(n)) iff there are some c\in \mathbb{R}^{+} and some n_0 \in \mathbb{N} s.t. (\forall n \geq n_0)(f(n)\leq c\times g(n)))

Complexity

f\in O(g): f is better than g

Complexity

Complexity

Complexity in Graphic

Complexity in Graphic

if f(x) and g(x) have the same complexity, then f \in O(g) as well as g \in O(f)

O(1)<O(log(log(n)))<O(log(n))<O(log(n)^2)<O(n)<O(n*log(n))<O(n^2)<O(2^n)<O(n!)

Sorting

Selection Sort

find_min and swapX

find_min and swapX

Programming Selection Sort

Auxiliary Functions

Libraries

Libraries

Asymptotic Complexity Analysis

Empirical Validation

Table of Content