Question: You will write a function (named havel_hakimi) that given a degree sequence, will determine whether or not it is graphical, in particular, an implementation of

You will 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: IN C++

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. How do you know if this trivial sequence is graphical?

A trivially graphical sequence is one consisting of all 0s, and a trivially non-graphical sequence is a sequence that contains negative numbers (since that makes no sense) or one where the sequence is too short to subtract x times.

You will write a function (named "havel_hakimi") that given a degree sequence,

INPUT OF THE TEST CASE ASSERT_EQ (havel_hakimi ("22211"), true); ASSERT_EQ ( havel_hakimi ("111100"), true); ASSERT_EQ (havel_hakimi ("5332210"), true); ASSERT_EQ (havel_hakimi("88886542100"), false); ASSERT_EQ(havel_hakimi ("00000"), true); ASSERT_EQ(havel hakimi ("10000"), false)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!