Advanced Formulation
1. Introduction
The definitions we proposed for and works well on most simple algorithms whose cost is a function of one parameter.
In general, if the cost depends on many parameters, there will be problems while estimating the complexity.
Furthermore, the algorithm itself can have non-deterministic behaviour, which sometimes can be described using some probability distribution.
Our proposed definition, while simple, cannot deal with these scenarios. And so, we will propose more robust definitions that work with those cases.
Finally, it is possible that the input itself follows some probability distribution, on which the algorithmic definitions maybe a little bit pessimistic. And with that we will introduce a definition for average case complexity
This section is very technical, and is intended only for those who can understand even the tiniest details. This chapter is as optional as it gets 😄.
2. Deterministic Algorithm
2.1 Introduction
We will start by deterministic algorithms, as they are the easiest to model.
A deterministic algorithm is an algorithm that gives the same output for the same input.
2.2 Notations
Let be an algorithm, that accepts inputs in some set
some unbounded function defining the size of the input
Let be the total cost of instructions that are executed while working with the input
Let be the maximum number of elementary instructions executed while working on input with size
Let some real valued function that is eventually strictly positive
3.4 Notation
By definition, we say that has time complexity if:
2.2 Notation
By definition, we say that has time complexity bound from below by g if:
Example 1
def sum(arr: Array[int]):
S=0
for a in arr:
S+=a
return S
For we have:
So we have:
3. Non-Deterministic Algorithm
Let be an algorithm, that accepts inputs in some set
some unbounded function defining the size of the input
Let the set of all possible executions for while accepting
Let be the total cost of instructions that are executed on the path
Let $ C^{W}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed while working on input with size executed on the worst path
Let $ C^{B}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed while working on input with size executed on the best path
Let some real valued function that is eventually strictly positive
4. Randomised Algorithm
4.1 Introduction
In many cases, for every input , the non-deterministic algorithm will have a random execution \Phi $ that follows some distribution $\mathcal{U}(X)
4.2 Notations
Let be an algorithm, that accepts inputs in some set
some unbounded function defining the size of the input
Let the set of all possible executions for while accepting
Let be a random execution while accepting
Let be the total cost of instructions that are executed on a random path
Let $ \tilde{C}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed on average while working on input with size
Let some real valued function that is eventually strictly positive
5. Deterministic Average Case Complexity
5.1 Introduction
In many cases, the input itself will follow some distribution
In that case, doing a supremum over all inputs of size is a pessimistic measure of complexity.
With the knowledge of we can estimate the average case complexity
5.2 Notations
- Let be an algorithm, that accepts inputs in some set
- Let be a random input
- some unbounded function defining the size of the input
- Let be the total cost of instructions that are executed on while accepting
5.3 Per Input size
5.4 Averaging over all Inputs
6. Non-Deterministic Average Case Complexity
6.1 Introduction
In many cases, the input itself will follow some distribution
In that case, doing a supremum over all inputs of size is a pessimistic measure of complexity.
With the knowledge of we can estimate the average case complexity
6.2 Notations
Let be an algorithm, that accepts inputs in some set
Let be a random input
some unbounded function defining the size of the input
Let be the total cost of instructions that are executed on while accepting
Let $ \tilde{C}_{\mathcal{A}}(x)$ defined as follow:
Let the set of all possible executions for while accepting
Let be the total cost of instructions that are executed on the path
Let $ C^{W}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed while working on input with size executed on the worst path
Let $ C^{B}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed while working on input with size executed on the best path
Let some real valued function that is eventually strictly positive
6.4 Averaging over all Inputs
7. Non-Deterministic Average Case Complexity
7.1 Introduction
In many cases, the input itself will follow some distribution
In that case, doing a supremum over all inputs of size is a pessimistic measure of complexity.
With the knowledge of we can estimate the average case complexity
7.2 Notations
Let be an algorithm, that accepts inputs in some set
Let be a random input
some unbounded function defining the size of the input
Let be a random execution while accepting
Let be the total cost of instructions that are executed on a random path
Let $ C^{B}_{\mathcal{A}}(x)$ defined as follow:
It is maximum number of elementary instructions executed while working on input with size executed on the best path
Let some real valued function that is eventually strictly positive