# Expected value with recurrences

I know that the expected value of a random variable X in a finite space S is $E(X) = \sum p(s)X(s)$ $\forall s \in S$, where $X(s)$ is the value of the random variable in the event $s$, and $p(s)$ is the probability of occurrence of $s$.

But I have seen in some recurrences with uniform distribution(for example quicksort algorithm) something like this:

$$T(n) = \sum_{i=1}^{n} \frac{1}{n} ( f(i)+ T(i) + T(n-i) )$$

where $f(i)$ is a function that depends on $i$, and $T(n)$ is the expected number of operations needed to perform some task with an array of size $n$. The part where I have my doubt is inside the parenthesis. This is not exactly the equivalent for $X(s)$ from above. The probability is $\frac{1}{n}$ for every term of the sum but the value of the implicit random variable is not precise. I mean that $X(s)$ is not $f(i) + T(i) + T(n-i)$ because $T(i)$ and $T(n-i)$ are expected values too, not values of random variables. $T(n)$ doesn't fit the definition of expected value given above.