In a random graph $G(n,p)$ where $n\geq 3$, let $S$ be the number of triples of nodes that are connected by exactly $2$ edges.
For example, if node $1$, node $2$ and node $3$ are connected by exactly $2$ edges, then $\{1,2,3\}$ is considered as one of the triples.
Find $E[S]$.
There can be at most $n$ such triples and at least 0 triples. Therefore, $E[S]=\sum_{k=0}^n k\cdot \text{Pr}(S=k)$.
Now the problem is that I don't know how to determine $\text{Pr}(S=k)$.
Assume a random graph with $n\;$vertices, such that each potential edge has probability $p$ of being an actual edge.
Let $f(n,p)$ be the expected number of qualifying triples.
There are $\large{\binom{n}{3}}$ candidate triples.
Each candidate contributes $0\;$or $1$ qualifying triples to the count of qualifying triples, hence each candidate contributes its probability of qualifying to the expected number of qualifying triples.
Then the probability that a randomly chosen candidate triple qualifies is $${\small{\binom{3}{2}}}p^2(1-p)$$ hence, since there are $\large{\binom{n}{3}}$ candidate triples, it follows that $$f(n,p)={\small{\binom{3}{2}}}p^2(1-p){\small{\binom{n}{3}}}$$