0

N-numbers , d1,d2,d3..dn are given. How do we check if it is possible to construct a undirected graph with vertices v1,v2,v3,...vn with degress d1,d2,...dn respectively. Graph should not contain multiple edges between the same pair of nodes, or "loop" edges (where both end vertices are the same node). Also, what is the running time of the algorithm ?

1 Answers1

4

This is what Wikipedia calls the graph realization problem, solvable by the Havel--Hakimi algorithm. Start with a graph having n vertices, v1..vn, and 0 edges. Define the deficit of a vertex vk to be the difference between dk and the current degree of vk. Repeatedly choose the vertex vk with the largest deficit D and connect it to the D other vertices having the D largest deficits. If a vertex would have negative deficit, then the instance is unsolvable. Otherwise, we terminate with a solution. I'll leave the running time as an exercise.

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120