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
Undirected is N^2. Simple - every node has N options of edges (himself included), total of N nodes thus N*N
Directed graph:
Question: What's the maximum number of edges in a directed graph with n vertices?
Answer:
n(n−1)
Undirected graph
Question: What's the maximum number of edges in an undirected graph with n vertices?
Answer:
(n*(n-1))/2
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.
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)
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.
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.
If you have
N
nodes, there areN - 1
directed edges than can lead from it (going to every other node). Therefore, the maximum number of edges isN * (N - 1)
.