When each node is connected to every other node then it means n nodes are connected to (n-1) nodes. But since the graph is undirected, edges in both the directions mean the same. Hence, the number of edges is divided by 2 to give the result as n(n-1)/2.