Tutorial 1 - Slides

Arrays

Action Time
Access Element Constant
Increase array size Linear (need to allocate new memory + copy over elements)
Insert into middle of aray Linear (usually new to allocate new memory, shift elements into insertion point)

Algorithms

Measure algorithms experimentally:

Issues with experimental analysis

Beyond experimental analysis

Develop an approach to analysing algorithm efficiency

Important details to measure

Theoretical Algorithm Analysis

  1. Describe using pseudocode
  2. Count primitive operations
  3. Describe the function of f(n)
    • Number of inputs (n)
    • Maximum/worst case number of primitive operations
  4. Perform asymptotic analysis

Asymptotic Analysis

Determine Big O, Ω\Omega, Θ\Theta bounds on runtime

f(n)  is  O(g(n))f(n) \; is \; O(g(n))

If there exists constants cc and n0n_{0} such that

f(n)cg(n)  for  all  n>n0 f(n) \le c\cdot g(n) \; for \;all \; n > n_{0}

Alt text

Function f(n)f(n) grows asymptotically no faster than g(n)g(n)

Big O

When we usually talk about asyptotic analysis, we use the following rules:

  1. Drop lower order terms and constants
  2. Make your bounds as tight as possible
  3. Simplify as much as possible

Important growth rates you need to know:

Name Notation
Constant 11
Logarithmic logn\log n
Linear nn
Log-linear nlognn \log n
Quadratic n2n^{2}
Cubic n3n^{3}
Exponential cnc^{n}
Factorial n!n!

Alt text

Big Ω\Omega

Is the lower bound

We say that f(n)Ω(g(n))f(n) \in \Omega (g(n)) if there exists a constant c>0c > 0 and integer n0n_{0} such that f(n)cg(n)f(n) \ge c \cdot g(n) for all n0>nn_{0} > n.

Big Θ\Theta

Is the tight bound.