educative.io

Formula to find possible edges in directed and undirected graph


#1

for Undirected graph formula should be n*(n-1) and directed it should be n*(n-1)/2. But in article it’s reversed.


#2

Can you explain the logic behind this?

An undirected graph has nC2 edges, which turns out to be n*(n-1)/2. By law, if an undirected graph becomes a directed graph, it will have twice the number of edges.

Undirected:
a – b

Directed:
a -> b
b -> a

Hence, the total number of edges in a directed graph would be:
2 * n*(n-1)/2 = n*(n-1)