I am trying to find the expected number of trails until the $k$-th failure or until the number of trials hit $n$, whichever comes first. The success probability of the trial is $p$.
My calculation gave me the below result. $$ \sum_{i=0}^{k-1} i{{n}\choose{i}} p^{n-i}(1-p)^{i} + \sum_{i=k}^n i { k-1+i \choose i} p^{i}(1-p)^k $$
But it seems the result is $$ \sum_{i=0}^{k-1} i{{n}\choose{i}} p^{n-i}(1-p)^{i} + \sum_{i=k}^n i { i-1 \choose k-1} p^{i-k}(1-p)^k $$
I don't know what is wrong with my result and how I can get the correct result.
Both expressions are wrong. The correct one is $$ \sum_{i=0}^{k-1} \color {red}n{{n}\choose{i}} p^{n-i}(1-p)^{i} + \sum_{i=k}^n i { i-1 \choose k-1} p^{i-k}(1-p)^k.\tag1 $$ Here the first term accounts for the events with the number of failures ($i $) in $n $ trials being less than $k $, and the second term accounts for the events with $k $ failures (the $k $-th failure being achieved in $i $-th trial).
The equation (1) can be written also in a more symmetric form: $$ n\sum_{i=0}^{k-1}{{n}\choose{i}} p^{n-i}(1-p)^{i} + k\sum_{i=k}^n { i\choose k} p^{i-k}(1-p)^k.\tag2 $$