16

In a directed acyclic graph with n vertices, what is the maximum possible number of directed edges in it?

panjiangwei
  • 163
  • 1
  • 1
  • 5
  • 1
    This 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
  • 3
    Not 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 Answers1

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