Complexity

  • Time Complexity
  • Space Complexity
    • We generally mean auxiliary space complexity which excludes space for the input

Asymptotic Notation

Syntax

  • All functions defined are for or its subset and the functions are asymptotically non-negative, that is the functions are non-negative for sufficiently large
  • When we say we actually mean
  • More precisely

Big Notations

  • Big-O
    • Upper bound
  • Big-Theta
    • Tight Bound
  • Big-Omega
    • Lower Bound
  • themselves aren’t inherently “worst-case”
  • Relationship between Big-Theta, Big-O and Big-Omega
  • Reflexivity of Big-Theta

little Notations

  • little-o
    • Strict upper bound
  • little-omega
    • Strict lower bound
  • Relationships between Big and little notations

Example with Asymptotic Notation

  • Assume worst case time complexity of an algorithm
  • Big-Omega
    • there are infinitely many lower bounds
  • small-omega
    • there are infinitely many strict lower bounds
  • Big-Theta
  • Big-O
    • there are infinitely many upper bounds
  • small-o
    • there are infinitely many strict upper bounds

Idea

  • = asymptotically strictly slower functions than
  • = asymptotically slower + same rate functions as
  • = asymptotically same rate functions as
  • = asymptotically faster + same rate functions as
  • = asymptotically faster functions than
  • Assume
    • : The functions represented by grow strictly faster than the functions represented by
    • : The functions represented by grow faster or same rate as functions represented by
  • Then
  • Comparison of common complexities

Complexity of Algorithms

  • Running Time is denoted by
  • Cases
    • Worst case
    • Average case
    • Best case
    • Amortized case
  • Default convention
    • When asked for an algorithm’s complexity, we usually analyze its worst-case complexity
    • We commonly express it using Big-O notation, often intending the tightest asymptotic upper bound
  • Why Big-O instead of Big-Theta?
    • Big-O is widely used as shorthand for algorithm complexity
    • Sometimes we cannot establish tight bound easily, hence Big-Theta cannot be used
    • When a tight bound is known, Big-Theta is perfectly valid and more informative

Average case complexity

  • We can compute using Probability distribution
  • Equal likely input case

Amortized case complexity

  • Very similar to equally likely average case
  • Example:
    • Time complexity for appending new element in dynamic array which internally performs resizing
  • Is it defined for sequence of operations???
  • How is it different from average case??