What is the maximum number of edges in a directed graph with n nodes? Is there any upper bound?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- d3.js moving average with previous and next data v
- How to get a fixed number of evenly spaced points
相关文章
- Mercurial Commit Charts / Graphs [closed]
- What are the problems associated to Best First Sea
- ceil conterpart for Math.floorDiv in Java?
- Coin change DP solution to keep track of coins
- why 48 bit seed in util Random class?
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
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
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 fromi
toj
iffi>j
.See here.
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).
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 isn(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 aren-2
edges that can be done. And so on. So the sum of all edges is:Since there are
(n-1)
terms in the Sum, and the average of Sum in such a series is((n-1)+1)/2
{(last + first)/2},Sum = n(n-1)/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).