I need to calculate average time complexity of the following pseudocode. It's not a homework, I am preparing for an exam, and it's going quite poorly so far. So all kind of tips are welcomed.
I am not sure if I should define recursive relation that would look +- like that:
$$\begin{cases} T(0) = 1 \\ T(n) = b_{n}T(n-1) + c_{n}\end{cases}$$
and then solve it to get my time complexity, or just somehow calculate time complexity straight away.
Some initial ideas: propability $p_{1}$ that $n > 0$ is $\frac{1}{n}$, therefore propability that instruction in 13rd row will execute is $p_{2} = 1 - p_{1} = 1 - \frac{1}{n}$
and 10th's row instruction is executed $n$ times.
So perhaps average time complexity should approximately look like that?
$$T_{avg}(n) = \underbrace{\sum_{i = 1}^{n}\frac{1}{n}(n-1)}_{\text{instruction 10}} + \overbrace{\sum_{i = 1}^{n}(1 - \frac{1}{n})1}^{\text{instruction 13}}$$
and then of course calculate it futher? How close am I?
I am mostly confused about lines $6, 7$ that imply recursion and how to tie up everything together.
All tips are welcomed. Thanks.
