In a directed acyclic graph with n vertices, what is the maximum possible number of directed edges in it?
Asked
Active
Viewed 2.2k times
16
-
1This question is off topic for Stack Overflow. You might try http://math.stackexchange.com/ which welcomes math questions at all levels. – Greg Hewgill Jul 28 '12 at 07:19
-
3Not to mention, this sounds like a homework problem. And I took the bait :-/ – Richard Sitze Jul 28 '12 at 07:21
-
Also, it's a duplicate of [How can I prove the maximum number of edges?](http://math.stackexchange.com/questions/61579/how-can-i-prove-the-maximum-number-of-edges) – Greg Hewgill Jul 28 '12 at 07:25
1 Answers
30
Assume N vertices/nodes, and let's explore building up a DAG with maximum edges. Consider any given node, say N1. The maximum # of nodes it can point to, or edges, at this early stage is N-1. Let's choose a second node N2: it can point to all nodes except itself and N1 - that's N-2 additional edges. Continue for remaining nodes, each can point to one less edge than the node before. The last node can point to 0 other nodes.
Sum of all edges: (N-1) + (N-2) + .. + 1 + 0 == (N-1)(N)/2

Richard Sitze
- 8,262
- 3
- 36
- 48
-
Hmm, [this](http://stackoverflow.com/questions/5058406/what-is-the-maximum-number-of-edges-in-a-directed-graph-with-n-nodes) seems to argue with the answer. – Realz Slaw Sep 13 '12 at 03:06
-
8@RealzSlaw The distinction is that a DAG is "acyclic"; the post you refer to discusses directed graphs in general. – Richard Sitze Sep 14 '12 at 04:24
-