87

What is the maximum number of edges in a directed graph with n nodes? Is there any upper bound?

bitFlipper
  • 475
  • 5
  • 20
Loolooii
  • 8,588
  • 14
  • 66
  • 90

12 Answers12

110

If you have N nodes, there are N - 1 directed edges than can lead from it (going to every other node). Therefore, the maximum number of edges is N * (N - 1).

Chris Smith
  • 18,244
  • 13
  • 59
  • 81
  • 16
    Correct. If edges are allowed to go from a node to itself, then the maximum is `N^2`. – ypercubeᵀᴹ Feb 22 '11 at 23:56
  • 3
    @M.A you are correct if you are talking about an undirected graph. In a directed graph however edge (A,B) is not the same as edge (B,A) – Bob9630 Feb 07 '14 at 22:30
  • 38
    N*(N-1) is number of edges in directed graph. Number of edge in undirected graph is (N * (N-1)) / 2 – Charles Chow May 23 '14 at 16:56
  • that is under the assumption that the graph is directed – moldovean Mar 21 '15 at 20:49
  • 1
    Same thought as @ypercube, the answer is correct but does not consider self-loops in the directed graph. – algarecu Oct 02 '15 at 09:13
  • What would be the answer in case of a simple Directed graph? If there is an edge from A to B and an edge from B to A that would the graph a Multigraph. –  Nov 29 '15 at 07:01
  • In an undirected graph, each edge is specified by its two endpoints and order doesn't matter. The number of edges is therefore the number of subsets of size 2 chosen from the set of vertices. Since the set of vertices has size n, the number of such subsets is given by the binomial coefficient C(n,2) (also known as "n choose 2"). Using the formula for binomial coefficients, C(n,2) = n(n-1)/2. Thus, there are n(n-1) directed edges & n(n-1)/2 undirected edges possible in a graph of size n. – Praween k Jul 07 '19 at 09:42
  • I am a bit confused here. For first point, N-1 is correct. But for second point it must be N-1-1(ie N-2) as we have already taken into account first point and connection is not allowed in opposite direction,and so on. What am I missing here? – Mandroid Jan 21 '23 at 06:19
55

Directed graph:

Question: What's the maximum number of edges in a directed graph with n vertices?

  • Assume there are no self-loops.
  • Assume there there is at most one edge from a given start vertex to a given end vertex.

Each edge is specified by its start vertex and end vertex. There are n choices for the start vertex. Since there are no self-loops, there are n-1 choices for the end vertex. Multiplying these together counts all possible choices.

Answer: n(n−1)

Undirected graph

Question: What's the maximum number of edges in an undirected graph with n vertices?

  • Assume there are no self-loops.
  • Assume there there is at most one edge from a given start vertex to a given end vertex.

In an undirected graph, each edge is specified by its two endpoints and order doesn't matter. The number of edges is therefore the number of subsets of size 2 chosen from the set of vertices. Since the set of vertices has size n, the number of such subsets is given by the binomial coefficient C(n,2) (also known as "n choose 2"). Using the formula for binomial coefficients, C(n,2) = n(n-1)/2.

Answer: (n*(n-1))/2

d.danailov
  • 9,594
  • 4
  • 51
  • 36
28

In an undirected graph (excluding multigraphs), the answer is n*(n-1)/2. In a directed graph an edge may occur in both directions between two nodes, then the answer is n*(n-1).

24

In addition to the intuitive explanation Chris Smith has provided, we can consider why this is the case from a different perspective: considering undirected graphs.

To see why in a DIRECTED graph the answer is n*(n-1), consider an undirected graph (which simply means that if there is a link between two nodes (A and B) then you can go in both ways: from A to B and from B to A). The maximum number of edges in an undirected graph is n(n-1)/2 and obviously in a directed graph there are twice as many.

Good, you might ask, but why are there a maximum of n(n-1)/2 edges in an undirected graph? For that, Consider n points (nodes) and ask how many edges can one make from the first point. Obviously, n-1 edges. Now how many edges can one draw from the second point, given that you connected the first point? Since the first and the second point are already connected, there are n-2 edges that can be done. And so on. So the sum of all edges is:

Sum = (n-1)+(n-2)+(n-3)+...+3+2+1 

Since there are (n-1) terms in the Sum, and the average of Sum in such a series is ((n-1)+0)/2 {(last + first)/2}, Sum = n(n-1)/2

moldovean
  • 3,132
  • 33
  • 36
6

If the graph is not a multi graph then it is clearly n * (n - 1), as each node can at most have edges to every other node. If this is a multigraph, then there is no max limit.

taskinoor
  • 45,586
  • 12
  • 116
  • 142
5

Putting it another way:

A complete graph is an undirected graph where each distinct pair of vertices has an unique edge connecting them. This is intuitive in the sense that, you are basically choosing 2 vertices from a collection of n vertices.

nC2 = n!/(n-2)!*2! = n(n-1)/2

This is the maximum number of edges an undirected graph can have. Now, for directed graph, each edge converts into two directed edges. So just multiply the previous result with two. That gives you the result: n(n-1)

QuestionEverything
  • 4,809
  • 7
  • 42
  • 61
2

In a directed graph having N vertices, each vertex can connect to N-1 other vertices in the graph(Assuming, no self loop). Hence, the total number of edges can be are N(N-1).

  • 1
    This answer doesn't contribute anything that is not already present in other answers. Also, `/2` is for an undirected graph. – Teepeemm Aug 09 '15 at 22:03
1

In the graph with self loop

max edges= n*n

such as we have 4 nodes(vertex)

4 nodes = 16 edges= 4*4
Harshith Rai
  • 3,018
  • 7
  • 22
  • 35
0

There can be as many as n(n-1)/2 edges in the graph if not multi-edge is allowed.

And this is achievable if we label the vertices 1,2,...,n and there's an edge from i to j iff i>j.

See here.

Tianyang Li
  • 1,755
  • 5
  • 26
  • 42
-1

Undirected is N^2. Simple - every node has N options of edges (himself included), total of N nodes thus N*N

Alon_T
  • 1,430
  • 4
  • 26
  • 47
  • N^2 includes repetition of directions so you count more than the actual edges. {1,2} is the same as {2,1} in undirected. In an **undirected graph** its `n(n-1)/2`. – BugShotGG Sep 04 '14 at 17:00
-1

The correct answer is n*(n-1)/2. Each edge has been counted twice, hence the division by 2. A complete graph has the maximum number of edges, which is given by n choose 2 = n*(n-1)/2.

ojh
  • 47
  • 1
  • 1
    This is only true if you **disallow directed cycles** in the graph. – István Zachar Feb 06 '12 at 11:14
  • 13
    This is only true for undirected graphs – Bandicoot Jul 30 '12 at 00:44
  • 2
    N*(N-1)/2 is only true for undirected graphs as edge count for each node decrease gradually from (n-1),(n-2),(n-3),....,1 (all gets sum into n(n-1)/2. However, for directed graphs you should consider an outword edge from each and every vertex and hence n(n-1). – Shailesh Pratapwar Jun 21 '14 at 12:50
-1

Can also be thought of as the number of ways of choosing pairs of nodes n choose 2 = n(n-1)/2. True if only any pair can have only one edge. Multiply by 2 otherwise

Kakira
  • 846
  • 1
  • 8
  • 14