Thinking about whether the Havel algorithm can form a simple graph by judging the degree sequence

Source: Internet
Author: User

Problem Description:

Given a list of n natural numbers D1, D2,..., dN, show how to decide in polynomial time whether There exists an undirected graph G = (V, E) whose node degrees is precisely the numbers D1, D2,,d N. G should not contain multiple edges between the same pair of nodes, or "loop" edges with both endpoints equal to The same node.

The problem is judging whether a simple graph can be formed from a sequence of degrees. The first statistic is whether the sum of the degrees is even, which is a necessary and sufficient condition for mapping. Then, according to the Havel theorem, it is assumed that the degree sequence contains n numbers, corresponding to n nodes, and the degree of the first node is di. The node is then sorted in descending order of degree size, then the first node is selected, and if the node is greater than n, it cannot form a simple graph, otherwise the D1 node after the first node is reduced by one degree, which can be understood as connecting the node to a larger D1 node. If you find that the degree of a node is less than 0 during a connection, you cannot form a simple diagram. After the first node is considered, the remaining nodes are re-sorted in descending order of degrees, n = n-1, repeating the above steps.

Here is the pseudo-code:
Total_degree = SUM (d) if!total_degree% 2:print ' no graph ' return-1n = length (d) while (n): sort (d) d1 = d[0]if D1 > N:prin T ' no simple graph ' return-1for i = 1 to d1:d[i]-= 1if D[i] < 0:print ' No simple graph ' return-1d[0] = 0n-= 1print ' t He sequence can construct a simple graph '

Correctness Proof:

The algorithm selects the maximum number of degrees each time the point is so that there are enough points to counteract the degree of the point, first of all, consider whether the algorithm to exclude the situation does not constitute a simple graph, its exclusion conditions include the sum of the degree is not even, the largest degree of more than a few nodes and the connection process has a negative degree point, The first one is the necessary and sufficient conditions for the diagram, and the second condition indicates that the node must have a ring or parallel edge, and the third condition indicates that the isolated node is connected, which is not allowed, so there must be a ring or parallel edge in the diagram. So the situation that the algorithm excludes is not a simple graph.

Is there a case that the algorithm succeeds in determining the sequence but does not constitute a simple graph? This is obviously impossible, because any simple diagram can be converted to each node is the number of degrees not less than its node's simple diagram, for example, first randomly find a node, connect other D1 nodes, then no longer consider the node, and then in the remaining nodes to find the most degree of the node, assigning it the second largest degree, That is, connect to the D2 node, and so on, until all the degrees are allocated.

In summary, the algorithm is correct.

Analysis of Complexity:

A traversal is nested in a sort, so the time complexity of the algorithm is O (n2logn).


Thinking about whether the Havel algorithm can form a simple graph by judging the degree sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.