Question
c++ write a function (named havel_hakimi) that given a degree sequence, will determine whether or not it is graphical, in particular, an implementation of the
c++ write a function (named "havel_hakimi") that given a degree sequence, will determine whether or not it is graphical, in particular, an implementation of the Havel-Hakimi algorithm. Your function will be as follows: It will accept a string with each character representing the degree of a different vertex, e.g. "1100" or "3211". It will output a boolean value of whether or not the degree sequence is graphical. The algorithm is remove the first number of the sequence and save it, say we call it x. Subtract 1 from the next x entries of the degree sequence and then resort descending. If this new sequence is graphical, then the original degree sequence is also graphical. Intuitively, you can repeat this process until the sequence is trivially graphical or trivially not. As an example for {3, 2, 2, 1}, we remove the 3 and then subtract 1 from the next 3 entries, resulting in a new sequence of {1, 1, 0}, now we do the same thing where we remove the first entry, and subtract 1 from the next 1 entry, resulting in a new sequence of {0, 0}. Recall, if this sequence is graphical, then so is the original.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started