3.1. Input in Sorted Order

In that case, we know the algorithm always uses 0 iterations of the loop:

`p_0=1, p_1 = 0, p_2 = 0, \ldots`

So the time is

`t_(text(loop)) = t_{text{init}} + \sum_{k=0}^{\infty} p_k ( (k+1)*t_{text{condition}} + k*t_{text{body}})`

but plugging in the p's simplifies to

`t_(text(loop)) = t_{text{init}} + t_{text{condition}} = O(1)`

For this input pattern, the entire algorithm has an average-case complexity of O(1).


In the Forum:

(no threads at this time)