In this case, we are equally likely to need 0 iterations, 1
iteration, 2 iterations , …, `n`

iterations. So the
iterations are all equally likely and we can use the "fixed bound &
equally probable" special case for loops.

`t_(text(loop)) = t_{text{init}} + O(1 + (M + N)/2 .
(t_{text{condition}} + t_{text{body}}))`

and, after our usual simplifications

`t_{text{loop}} = O(n)`

And we can then replace the entire loop by `O(n)`.

And now, we add up the complexities in the remaining straight-line sequence, and conclude that the entire algorithm has an average case complexity of O(n) when presented with randomly arranged inputs.

This is the same result we had for the worst case analysis. That's not unusual.

Under similar randomly arranged inputs, the average case complexity of ordered search is O(n) and the average case complexity of binary search is O(log n) Again, these are the same as their worst-case complexities.

## In the Forum: