Skip to main content

3. Big-O (2)

10/02/23

Classification of Functions

Often need a way to group together functions by their scaling behaviour, and the classification should

  • Remove unnecessary details
  • Be (relatively) quick and easy
  • Be able to deal with weird functions that can happen to runtime
  • Still be mathematically well-defined

Ratios vs. big-Oh

  • f(n)f(n) can be O(g(n))O(g(n)) even if the ratio f(n)/g(n)f(n)/g(n) does not exist
  • Therefore, big-Oh can be used in situations that ratios cannot
  • The possibility of 'weird functions' means that big-Oh is more suitable than ratios for doing analysis of efficiency of programs

Binary relations, R, are characterised by potential properties:

  • Reflexive - xRxxRx
  • Symmetric - xRyxRy iff RxRx
  • Transitive - xRyxRy & yRzxRzyRz \to xRz

Reflexive

  • Trivial for any function
  • f(n)f(n) is O(f(n))O(f(n))
  • as just take c=1c=1, and use n.f(n)f(n)\forall n.f(n)\le f(n)

Symmetric

  • Big-Oh is NOT symmetric
  • 11 is O(n)O(n) but nn is not O(1)O(1)
  • Only takes one counterexample to show that we cannot say it is symmetric

Transitive

  • Given ff is O(g)O(g) and gg is O(h)O(h) we can show ff is O(h)O(h)

Set

  • Big Oh as a binary relation is reflexive and transitive but not symmetric
  • May help to thing of O(n)O(n) as a set of functions with each function f in the set, fO(n)f\in O(n) satisfying ff is O(n)O(n)
  • Behaves like ,,\subseteq,\in,\le but not ==

Rules for quick big-Oh proofs

  • Reverting the definition each time is time-consuming and error prone
  • Better to develop a set of rules that allow us to very quickly find big-Oh

Multiplication Rule