Asymptotic complexity of algorithms: Difference between revisions
No edit summary |
|||
Line 12: | Line 12: | ||
# The number of nodes and the number of edges/arcs in a [[Basic graph definitions#Directed and undirected graphs|graph]]. | # The number of nodes and the number of edges/arcs in a [[Basic graph definitions#Directed and undirected graphs|graph]]. | ||
== Asymptotic complexity == | == Asymptotic complexity of an algorithm == | ||
# For a selection of <math>k</math> characterizing parameters for an [[Algorithms and correctness#Algorithmic problem|algorithmic problem]], let <math>\mathcal{I}(n_1,\ldots,n_k)</math> denote the set of all instances for which these parameters assume the values <math>n_1,\ldots,n_k</math>. | # For a selection of <math>k</math> characterizing parameters for an [[Algorithms and correctness#Algorithmic problem|algorithmic problem]], let <math>\mathcal{I}(n_1,\ldots,n_k)</math> denote the set of all instances for which these parameters assume the values <math>n_1,\ldots,n_k</math>. | ||
# For an [[Algorithms and correctness#Algorithm|algorithm]] for this algorithmic problem, the '''asymptotic complexity''' of the algorithm with respect to this selection of characterizing parameters is defined as follows. | # For an [[Algorithms and correctness#Algorithm|algorithm]] for this algorithmic problem, the '''asymptotic complexity''' of the algorithm with respect to this selection of characterizing parameters is defined as follows. | ||
## In the '''worst case''': by the function <math> | ## In the '''worst case''': by the function <math>f_1:\mathbb{N}^k\rightarrow\mathbb{R}^+</math> such that <math>f_\max(n_1,\ldots,n_k)</math> is the ''maximum'' number of operations executed by the algorithm for any instance is <math>\mathcal{I}(n_1,\ldots,n_k)</math>. | ||
## In the '''best case''': by the function <math> | ## In the '''best case''': by the function <math>f_2:\mathbb{N}^k\rightarrow\mathbb{R}^+</math> such that <math>f_\min(n_1,\ldots,n_k)</math> is the ''minimum'' number of operations executed by the algorithm for any instance is <math>\mathcal{I}(n_1,\ldots,n_k)</math>. | ||
## In the '''average case''': For this case, a [[http://en.wikipedia.org/wiki/Probability_distribution probability distribution]] over each set <math>\mathcal{I}(n_1,\ldots,n_k)</math> is required. Then the asymptotic average complexity is the function <math> | ## In the '''average case''': For this case, a [[http://en.wikipedia.org/wiki/Probability_distribution probability distribution]] <math>P</math> over each set <math>\mathcal{I}(n_1,\ldots,n_k)</math> is required. Then the asymptotic average complexity is the function <math>f_P:\mathbb{N}^k\rightarrow\mathbb{R}^+</math> such that <math>f_P(n_1,\ldots,n_k)</math> is the ''expected'' number of operations executed by the algorithm for any instance is <math>\mathcal{I}(n_1,\ldots,n_k)</math>. | ||
== Bounds on the asymtptotic complexity == | |||
Consider an [[Algorithms and correctness#Algorithmic problem|algorithmic problem], a selection of <math>k</math> [[#Characterizing parameters|characteristizing parameters]], and an [[Algorithms and correctness#Algorithm|algorithm]] for this algorithmic problem. Moreover, let <math>f_\max</math>, <math>f_\min</math>, and <math>f_P</math> be defined as [[#Asymptotic complexity of an algorithm|here]]. | |||
For a function <math>f_1:\mathbb{N}^k\rightarrow\mathbb{R}^+</math>, we say that the algorithm is in <math>\oplus(g)</math> in the worst (resp., best, average) case if <math>f_\max\in\oplus(g)</math> (resp., <math>f_\min\in\oplus(g)/</math>, <math>f_\min\in\oplus(g)/</math>), where "<math>\oplus</math>" is one of "<math>\mathcal{O}</math>", "<math>o</math>", "<math>\Omega</math>", and "<math>\Theta</math>". |
Revision as of 13:11, 28 May 2015
Asymptotic complexity vs. run time
- Roughly speaking, the run time of an algorithm is measured by the number of operations executed by the machine.
- However, in theoretical considerations, the run time is estimated by the algorithm's asymptotic complexity. In asymptotic considerations, constant multiplicative factors are completely disregarded. Therefore, 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 characterizing (numerical) 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:
- The number of elements in sets, maps, and sequences and the (maximum) size of an element in a set, map, or sequence.
- The number of nodes and the number of edges/arcs in a graph.
Asymptotic complexity of an algorithm
- For a selection of [math]\displaystyle{ k }[/math] characterizing parameters for an algorithmic problem, let [math]\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }[/math] denote the set of all instances for which these parameters assume the values [math]\displaystyle{ n_1,\ldots,n_k }[/math].
- 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.
- In the worst case: by the function [math]\displaystyle{ f_1:\mathbb{N}^k\rightarrow\mathbb{R}^+ }[/math] such that [math]\displaystyle{ f_\max(n_1,\ldots,n_k) }[/math] is the maximum number of operations executed by the algorithm for any instance is [math]\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }[/math].
- In the best case: by the function [math]\displaystyle{ f_2:\mathbb{N}^k\rightarrow\mathbb{R}^+ }[/math] such that [math]\displaystyle{ f_\min(n_1,\ldots,n_k) }[/math] is the minimum number of operations executed by the algorithm for any instance is [math]\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }[/math].
- In the average case: For this case, a [probability distribution] [math]\displaystyle{ P }[/math] over each set [math]\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }[/math] is required. Then the asymptotic average complexity is the function [math]\displaystyle{ f_P:\mathbb{N}^k\rightarrow\mathbb{R}^+ }[/math] such that [math]\displaystyle{ f_P(n_1,\ldots,n_k) }[/math] is the expected number of operations executed by the algorithm for any instance is [math]\displaystyle{ \mathcal{I}(n_1,\ldots,n_k) }[/math].
Bounds on the asymtptotic complexity
Consider an [[Algorithms and correctness#Algorithmic problem|algorithmic problem], a selection of [math]\displaystyle{ k }[/math] characteristizing parameters, and an algorithm for this algorithmic problem. Moreover, let [math]\displaystyle{ f_\max }[/math], [math]\displaystyle{ f_\min }[/math], and [math]\displaystyle{ f_P }[/math] be defined as here.
For a function [math]\displaystyle{ f_1:\mathbb{N}^k\rightarrow\mathbb{R}^+ }[/math], we say that the algorithm is in [math]\displaystyle{ \oplus(g) }[/math] in the worst (resp., best, average) case if [math]\displaystyle{ f_\max\in\oplus(g) }[/math] (resp., [math]\displaystyle{ f_\min\in\oplus(g)/ }[/math], [math]\displaystyle{ f_\min\in\oplus(g)/ }[/math]), where "[math]\displaystyle{ \oplus }[/math]" is one of "[math]\displaystyle{ \mathcal{O} }[/math]", "[math]\displaystyle{ o }[/math]", "[math]\displaystyle{ \Omega }[/math]", and "[math]\displaystyle{ \Theta }[/math]".