Now, that's only one possible scenario in which the inputs are almost sorted. Let's look at another. Suppose that we knew that, for each successive input, the probability of it appearing in the input `m` steps out of its correct position is proportional to `1/(m+1)` (i.e., each additional step out of its correct position is progressively more unlikely). Then we have
The constant `c` is necessary because the sum of all the probabilities must be exactly 1. We can compute the value of `c` by using that fact:
This sum, for reasonably large n, is approximately `log n`.
So we conclude that `c` is approximately `= 1/log(n)`.
So the function, for this input distribution, is
S o the average case is slightly smaller than the worst case, though not by much (remember that `log n` is nearly constant over large ranges of `n`, so `n/(log(n))` grows only slightly slower than `n`.