# Asymptotic complexity of algorithms

## Asymptotic complexity vs. run time

1. Roughly speaking, the run time of an algorithm is measured by the number of operations executed by the machine.
2. However, in theoretical considerations, the run time is estimated by the algorithm's asymptotic complexity. In asymptotic considerations, constant multiplicative factors are completely disregarded. For that, it does not matter how fast the machine and how smart the algorithm's implementation is.

## Characterizing parameters

For the inputs of an algorithmic problem, one or more (numerical) characterizing parameters are to be selected, from which the total size of an input can be computed (or, at least, quite tightly bounded from above and from below).

Examples:

1. The number of elements in sets, maps, and sequences and the (maximum) size of an element in a set, map, or sequence.
2. The number of nodes and the number of edges/arcs in a graph.

## Asymptotic complexity of an algorithm

1. For a selection of $\displaystyle{ k }$ characterizing parameters for an algorithmic problem, let $\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }$ denote the set of all instances for which these parameters assume the values $\displaystyle{ n_1,\ldots,n_k }$.
2. For an algorithm for this algorithmic problem, the asymptotic complexity of the algorithm with respect to this selection of characterizing parameters is defined as follows.
1. In the worst case: by the function $\displaystyle{ f_\max:\mathbb{N}^k\rightarrow\mathbb{R}^+ }$ such that $\displaystyle{ f_{\max} (n_1,\ldots,n_k) }$ is the maximum number of operations executed by the algorithm for any instance in $\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }$.
2. In the best case: by the function $\displaystyle{ f_\min:\mathbb{N}^k\rightarrow\mathbb{R}^+ }$ such that $\displaystyle{ f_{\min}(n_1,\ldots,n_k) }$ is the minimum number of operations executed by the algorithm for any instance in $\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }$.
3. In the average case: For this case, a probability distribution $\displaystyle{ P_{n_1,\ldots,n_k} }$ over each set $\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }$ is required. For short, let $\displaystyle{ P:=(P_{n_1,\ldots,n_k})_{n_1,\ldots,n_k\in\mathbb{N}} }$. Then the asymptotic average complexity is the function $\displaystyle{ f_P:\mathbb{N}^k\rightarrow\mathbb{R}^+ }$ such that $\displaystyle{ f_P(n_1,\ldots,n_k) }$ is the expected number of operations executed by the algorithm, taken over all instances in $\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }$, with respect to the distribution $\displaystyle{ P_{n_1,\ldots,n_k} }$.

## Bounds on the asymtptotic complexity

Consider an algorithmic problem, a selection of $\displaystyle{ k }$ characteristizing parameters, and an algorithm for this algorithmic problem. Moreover, let $\displaystyle{ f_\max }$, $\displaystyle{ f_\min }$, and $\displaystyle{ f_P }$ be defined as above.

For a function $\displaystyle{ f_1:\mathbb{N}^k\rightarrow\mathbb{R}^+ }$, we say that the algorithm's complexity (the algorithm, for short) is in $\displaystyle{ \oplus(g) }$

1. in the worst case, if $\displaystyle{ f_{\max}\in\oplus(g) }$,
2. in the best case, if $\displaystyle{ f_{\min}\in\oplus(g) }$,
3. in the average case with respect to $\displaystyle{ P }$, if $\displaystyle{ f_P\in\oplus(g) }$,

where "$\displaystyle{ \oplus }$" is one of "$\displaystyle{ \mathcal{O} }$", "$\displaystyle{ o }$", "$\displaystyle{ \Omega }$", and "$\displaystyle{ \Theta }$".

## Asymptotic complexity analysis of an algorithm

An asymptotic complexity analysis of an algorithm combines two aspects: (1) which case (worst, best, average) is to be analyzed and (2) which type of function class ($\displaystyle{ \mathcal{O} }$, $\displaystyle{ \Omega }$, $\displaystyle{ \Theta }$, $\displaystyle{ o }$) is to be determined. Note that the case and the function class are two separate concepts, which are easily confused.