Expected local clustering coefficient for a node in a network For an assignment for university I have to explain why the expected clustering coefficient is equal to
$$
\sum^{N-1}_{k=1}p(k) \cdot \sum^{k(k-1)/2}_{i=0} \frac{i}{k(k-1)/2} \cdot Binom[i; k(k-1)/2; p]
$$
and why this can also simply be written as $p$.
I have no idea where or how to start explaining why this is the case, nor is any further explanation given in the assignment.
 A: The formula seems to assume an Erdos-Renyi random graph, i.e., each vertex pair is connected with a fixed probability $p$.
Given a vertex set $V$ with $|V| = n$, consider the probability space $(\mathcal{G}\times V, \mathcal{F},\mathbb{P})$, where $\mathcal{G}$ is the set of all graphs on $V$. Let $c(G,x)$ be the local clustering coefficient of vertex $x \in V$ in graph $G \in \mathcal{G}$. 
In the case of an Erdos-Renyi random graph with parameter $p$ $$ \mathbb{P}(\{(G,x)\}) = \frac{1}{n}p^{|E(G)|}(1-p)^{\binom{n}{2} - |E(G)|}$$
The local clustering coefficient of a vertex $x$ in graph $G$ is the fraction of vertex pairs in the neighborhood of $x$ that have an edge between them.
$$c(G,x) = \frac{|\{y,z\} : \{x,y\},\{x,z\},\{y,z\} \in E(G) |}{|\{y,z\} : \{x,y\},\{x,z\} \in E(G) |} = \frac{|\{y,z\} : \{x,y\},\{x,z\},\{y,z\} \in E(G) |}{\binom{\deg(x)}{2}}$$
The expected local clustering coefficient is 
\begin{align} 
\mathbb{E}[c(G,x)] 
&= \mathbb{E}[\mathbb{E}[c(G,x)|x]] \\
&= \mathbb{E}\left[\mathbb{E}\left[ \left.\frac{\textrm{#edges among neighbors of }x}{\binom{\deg(x)}{2}}\right|x\right]\right] \\ 
&= \mathbb{E}\left[ \frac{1}{ \binom{\deg(x)}{2} } \mathbb{E}\left[\left. \sum_{\{\{y,z\}:\{x,y\}, \{x,z\}\in E\}} \mathbb{1}_{ \{y,z\} \in E }\right|x\right]\right] \\ 
&= \mathbb{E}\left[ \frac{1}{ \binom{\deg(x)}{2} } \sum_{\{\{y,z\}:\{x,y\}, \{x,z\}\in E\}} \mathbb{E}\left[\left.  \mathbb{1}_{ \{y,z\} \in E }\right|x\right]\right] \\ 
&= \mathbb{E}\left[ \frac{1}{ \binom{\deg(x)}{2} } \sum_{\{\{y,z\}:\{x,y\}, \{x,z\}\in E\}} \mathbb{P}\left(\left.  \{y,z\} \in E \right|x\right)\right] \\ 
&= \mathbb{E}\left[ \frac{1}{ \binom{\deg(x)}{2} } \sum_{\{\{y,z\}:\{x,y\}, \{x,z\}\in E\}} p\right] = \mathbb{E}\left[ \frac{1}{ \binom{\deg(x)}{2} } p \binom{\deg(x)}{2}  \right] =p
\end{align}
But this can also be written as 
\begin{align} 
\mathbb{E}[c(G,x)] 
&= \mathbb{E}\left[\mathbb{E}\left[ \left.\frac{\textrm{#edges among neighbors of }x}{\binom{\deg(x)}{2}}\right|x\right]\right] \\
&= \mathbb{E}\left[ \sum_{i=0}^{\binom{\deg{x}}{2}}\underbrace{\mathbb{P}( i \textrm{ edges among neighbors of }x| x)}_{\mathrm{Binom}(i;\deg(x),p)} \;\frac{i}{\binom{\deg(x)}{2}}    \right] \\ 
&= \sum_{k=0}^{N-1} \underbrace{\mathbb{P}(\deg(x) = k)}_{\mathrm{Binom}(k;N-1,p)} \sum_{i=0}^{\binom{k}{2}}  \; \underbrace{\mathbb{P}( i \textrm{ edges among neighbors of }x|\mathrm{degree}(x) = k)}_{\mathrm{Binom}\left(i;\binom{k}{2},p\right)} \;\frac{i}{\binom{k}{2}}
\end{align}
