8

There are 'n' vertices and 0 edges of an undirected graph. What can be the maximum number of edges that we can draw such that the graph remains disconnected.

I have made the solution that we can exclude one vertex and can find the maximum number of edges between n-1 vertices of undirected graph, so that the graph still remains disconnected.

which is n(n-1)/2 for n vertices and will be (n-1)(n-2)/2 for n-1 vertices. Can there be a better solution?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Luv
  • 5,381
  • 9
  • 48
  • 61
  • I'm voting to close this question as off-topic because it's a math question, not a programming one. – TylerH Mar 03 '19 at 20:42

3 Answers3

7

You can resolve this using analysis. Take your idea and generalize it. You divide the n vertices in two groups , of size x and n-x. Now the number of edges is a function of x, expressed by

  f(x)= x(x-1)/2 + (n-x)(n-x-1)/2
  f(x) = 1/2(2x^2 - 2nx +n^2 - n)

The value which maximize this function is the partition size you want. If you make calculation you find that it decrease from x=0 to x=n/2, then increase to x=n. As x = 0 or x = n means the graph is collected, you take the next greatest value which is x=1. So your intuition is optimal.

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • 1
    +1 This solution proves why the answer given is also a local maximum. To completely cover yourself, you might also want to find f'', and find out that `f''(MIN) < 0`, and also validate that f(n),f(0) are not feasible solutions, and validates f(1),f(n-1) – amit Apr 08 '12 at 11:34
  • Yes of course, I was not reading it throughfully, I was just looking at the principiles of this approach, which is flawless in my opinion. – amit Apr 08 '12 at 11:36
3

Your solution should be the best solution.

Because any new edge added must have the nth vertex at one end.

sukunrt
  • 1,523
  • 10
  • 20
  • 2
    The reason provided `"beacuse any new edge added must have the nth vertex at one end"` provides explanation why it is a *local maximum* and not a *global maximum*. This explanation does not cover solutions with completely different structure, which could have more edges - without an apropriate proof why they could not. – amit Apr 08 '12 at 11:27
  • The number of edges for a multigraph are obviously infinite. Now if it cannot have self loops then you have to select two vertices to add an edge. You have completely connected the first (n-1) vertices. To add one more edge both the vertices cannot come from the initial set of n-1 vertices because you have made every edge possible from the initial n-1 vertices. So one of the edges has to be the nth one. If you have self loops allowed then you can add n more edges because self loops don't add to connectivity. – sukunrt Apr 08 '12 at 12:09
  • 1
    That doesn't at all cover the possibility of graphs consisting of two complete subgraphs of sizes different than 1,n-1. The solution is (accidentaly) right, but the reasoning is not. – voidengine Apr 08 '12 at 12:53
  • nC2 is O(n^2). So k^2 + r^2 will be less than (k+r)^2. – sukunrt Apr 08 '12 at 18:19
0

If graph can have multi edges, answer is infinity for n>=3.
If it can also contain self-loops, answer is infinity for n>=2,

If none of those holds your solution is correct.

kilotaras
  • 1,419
  • 9
  • 24