Skip to content
Sahithyan's S2
1
Sahithyan's S2 — Data Structures and Algorithms

Complexity Analysis

A way of comparing different algorithms. Algorithms’ time to run is hard to measure exactly and hard to compare with fairness. And also there are too many uncontrollable variables in measuring the actual time. Because of that, the algorithms are analyzed asymptotically: a way of measuring the performance of an algorithm without depending on hardware.

  • The algorithm might not reach the limit after which the asymptotic behaviour is seen
    Different algorithms can be used for different input ranges
  • The input density and input size might not be uniform
    Usually assumed to be uniform and is considered good enough. Experimentation is required for more precise approximation.
  • Not all functions (such as periodic, oscillating functions) can be compared

A method used to categorize functions or to calculate upper/lower bounds with respect to the growth rate of functions. In this context, total number of steps followed by a specific algorithm is expressed in terms of its input size nn, then asymptotic analysis can be done.

Analysis of how the running time of the algorithm grows with various input sizes.

Instead of measuring the running time of the algorithm for specific inputs, how the running time increases with the increasing input size.

Analysis of additional space required for an algorithm to run.

There are more than one asymptotic notations. All these are sets of functions.

Suppose f,gf,g are 2 functions of nn.

f(n)O(g(n))f(n) \in O(g(n)) iff c>0n0N    s.t\exists\, c \gt 0 \land n_0 \in \mathbb{N}\;\; \text{s.t}:

nn0,  f(n)cg(n)\forall n \ge n_0,\; f(n) \le c* g(n)

An asymptotic upper bound.

f(n)Ω(g(n))f(n) \in \Omega(g(n)) iff c>0n0N    s.t\exists\, c \gt 0 \land n_0 \in \mathbb{N}\;\; \text{s.t}:

nn0,  f(n)cg(n)\forall n \ge n_0,\; f(n) \ge c* g(n)

An asymptotic lower bound.

f(n)Θ(g(n))f(n) \in \Theta(g(n)) iff c1,c2>0n0N    s.t\exists\, c_1, c_2 \gt 0 \land n_0 \in \mathbb{N}\;\; \text{s.t}:

nn0,  c1g(n)f(n)c2g(n)\forall n \ge n_0,\; c_1 * g(n) \le f(n) \le c_2* g(n)

An asymptotic equivalence. A tight characterization unlike Big-O or Big-Omega.

Denoted by O\overline{O}. Similar to Big-O but the logarithmic terms are removed in the analysis. Not used as much as the other three.

f(n)o(g(n))f(n) \in o(g(n)) iff ϵ>0,  N  s.t\forall \epsilon \gt 0,\;\exists N\;\text{s.t}:

nN,  f(n)ϵg(n)\forall n \ge N,\;|f(n)|\le\epsilon|g(n)|

Strict upper bound characterization.

Implies Big-O.

f(n)o(g(n))    f(n)O(g(n))f(n) \in o(g(n)) \implies f(n) \in O(g(n))

Implies “not Big-Theta”.

f(n)o(g(n))    f(n)∉Θ(g(n))f(n) \in o(g(n)) \implies f(n) \not\in \Theta(g(n))

f(n)ω(g(n))f(n) \in \omega(g(n)) iff ϵ>0,  N  s.t\forall \epsilon \gt 0,\;\exists N\;\text{s.t}:

nN,  f(n)ϵg(n)\forall n \ge N,\;|f(n)|\ge\epsilon|g(n)|

Strict lower bound characterization.

Implies Big-Omega.

f(n)ω(g(n))    f(n)Ω(g(n))f(n) \in \omega(g(n)) \implies f(n) \in \Omega(g(n))

Implies “not Big-Theta”.

f(n)ω(g(n))    f(n)∉Θ(g(n))f(n) \in \omega(g(n)) \implies f(n) \not\in \Theta(g(n))
NameDefinition
Little-olimnf(n)g(n)=0\lim_{n \to \infty}{\frac{f(n)}{g(n)}}=0
Big-Olimnf(n)g(n)[0,)\lim_{n \to \infty}{\frac{f(n)}{g(n)}} \in [0,\infty)
Big-Thetalimnf(n)g(n)R+\lim_{n \to \infty}{\frac{f(n)}{g(n)}}\in\mathbb{R}^{+}
Little-omegalimnf(n)g(n)>0\lim_{n \to \infty}{\frac{f(n)}{g(n)}}\gt 0
Big-Omegalimnf(n)g(n)=\lim_{n \to \infty}{\frac{f(n)}{g(n)}}=\infty

If f(n)=O(g(n))f(n) = O(g(n)) and g(n)=O(h(n))g(n) = O(h(n)) then f(n)=O(h(n))f(n) = O(h(n)). Applies to all 5 functions.

  • f(n)=O(f(n))f(n) = O(f(n))
  • f(n)=Ω(f(n))f(n) = \Omega(f(n))
  • f(n)=Θ(f(n))f(n) = \Theta(f(n))
f(n)=O(g(n))    g(n)=Ω(f(n))f(n) = O(g(n)) \iff g(n) = \Omega(f(n)) f(n)=o(g(n))    g(n)=ω(f(n))f(n) = o(g(n)) \iff g(n) = \omega(f(n)) f(n)O(g(n))    g(n)Ω(f(n))f(n) \in O(g(n)) \iff g(n) \in \Omega(f(n)) f(n)Θ(g(n))    f(n)O(g(n))f(n)Ω(g(n))f(n) \in \Theta(g(n)) \implies f(n) \in O(g(n)) \land f(n) \in \Omega(g(n)) f(n)Θ(g(n))    g(n)Θ(f(n))f(n) \in \Theta(g(n)) \iff g(n) \in \Theta(f(n))

Time elapsed from start of the process to “now” when measured by a stopwatch.

Time spent in user code.

Time spent in kernel code.