Consider the following algorithm to perform the inversion of certain function F given a witness F(K) = W so that we can recover the key. It basically checks all the possible values and yield those who map to the witness value. Here N is the size of the domain of F and M is the size of the image of F.
Input: an image w
1: shuffle K with a random permutation
2: for all i = 1 to N do
3: if F(ki) = w then
4: yield ki and stop
5: end if
6: end for
While proving that the expected complexity is M for $N >> M$ I have trouble understanding the following claimed equality:
$\sum_{i=0}^{N-1} i P[\text{complexity} = i] = \sum_{i = 0}^{N-1} P[\text{complexity} > i]$
Why is it the case? I understand that $P[\text{complexity} > i] = \big(1-\frac{1}{M}\big)^i$ and although not stated I think that $P[\text{complexity} = i]$ should be $ \big(1-\frac{1}{M}\big)^i\frac{1}{M}$
If $X$ is a random variable that assumes nonnegative integer values, then:
$$\begin{align*} \sum \limits_{i = 0}^{N - 1} P(X > i) &= \sum \limits_{i = 0}^{N - 1} \sum \limits_{j = 0}^\infty I\{j > i\}P(X = j) = \sum \limits_{j = 0}^\infty \sum \limits_{i = 0}^{N - 1} I\{j > i\} P(X = j) \\ &= \sum \limits_{j = 0}^\infty P(X = j)\sum \limits_{i = 0}^{ \min(N, j) - 1} 1 = \sum \limits_{j = 0}^\infty \min(N, j)P(X = j) \end{align*}$$
This means that your equation holds iff the complexity is at most $N$.