简体   繁体   English

找出图中的最大边数

[英]Find the maximum number of edges in the graph

There are 'n' vertices and 0 edges of an undirected graph.无向图有'n'个顶点和0条边。 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.我已经做了解决方案,我们可以排除一个顶点,并且可以找到无向图的n-1个顶点之间的最大边数,使得该图仍然不连通。

which is n(n-1)/2 for n vertices and will be (n-1)(n-2)/2 for n-1 vertices.对于 n 个顶点是 n(n-1)/2,对于 n-1 个顶点是 (n-1)(n-2)/2。 Can there be a better solution?能有更好的解决办法吗?

You can resolve this using analysis.您可以使用分析解决此问题。 Take your idea and generalize it.接受你的想法并将其概括。 You divide the n vertices in two groups, of size x and nx .您将 n 个顶点分成两组,大小为xnx Now the number of edges is a function of x , expressed by现在边的数量是x的 function,表示为

  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.最大化这个 function 的值就是你想要的分区大小。 If you make calculation you find that it decrease from x=0 to x=n/2 , then increase to x=n .如果您进行计算,您会发现它从x=0减少到x=n/2 ,然后增加到x=n As x = 0 or x = n means the graph is collected, you take the next greatest value which is x=1 .由于 x = 0 或 x = n 表示图形已收集,因此您取下一个最大值x=1 So your intuition is optimal.所以你的直觉是最优的。

Your solution should be the best solution.你的解决方案应该是最好的解决方案。

Because any new edge added must have the nth vertex at one end.因为添加的任何新边都必须在一端具有第 n 个顶点。

If graph can have multi edges, answer is infinity for n>=3.如果图可以有多条边,则 n>=3 的答案是无穷大。
If it can also contain self-loops, answer is infinity for n>=2,如果它也可以包含自循环,那么当 n>=2 时答案是无穷大,

If none of those holds your solution is correct.如果这些都不成立,则您的解决方案是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM