Analysis of Algorithms

Worst-Case Analysis

Asymptotic Analysis

Used to describe the run-time cost of functions.

Big-O

Big-O means that a function is “bounded above” by another function.
For example, means that f is bounded above by g.

Formally, , iff .

For example, consider .
We can say:

  • but we could also say…

Big Omega

Examples of some algorithms

Linear Time Algorithms

  • Computing the maximum (or minimum) of an unordered list of numbers
    • Takes time to look at all the input
  • Merging two sorted lists
    • For two lists of size , it takes steps because you move forward down one list each time you iterate

Quadratic Time Algorithms

  • Enumerate all pairs of elements
  • Find the distance between the closest algorithm (though a faster solution exists)

Input Structure Challenge

  • Without taking advantage of it being sorted, just use a hashmap
  • ff

Cubic Time Algorithms

Exponential Time Algorithms

Summary (Tips)

  • Learn , , notation
  • Use worst-case analysis often (try to prevent the worst from happening)
  • Focus on running-time
  • Polynomial good, exponential bad