Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rumor spreading problem: There are n people, each in possession of a different r

ID: 3764293 • Letter: R

Question

Rumor spreading problem: There are n people, each in possession of a different rumor. They want to share all the rumors with each other by sending electronic messages. Assume that a sender includes all the rumors he or she knows at the time the message is sent and that a message may only have one addressee.
a. Design a greedy algorithm that always yields the minimum number of messages they need to send to guarantee that every one of them gets all the rumors
b. Give the efficiency of your proposed algorithm as a function of n

Explanation / Answer

Bridge crossing revisited Consider the generalization of the bridge cross- ing puzzle (Problem 2 in Exercises 1.2) in which we have q A 1 people whose bridge crossing times are w 1 > w 2 > ===> w q = All the other conditions of the problem remain the same: at most two people at the time can cross the bridge (and they move with the speed of the slower of the two) and they must carry with them the only ashlight the group has. Design a greedy algorithm for this problem and f nd how long it will take to cross the bridge by using this algorithm. Does your algorithm yields a minimum crossing time for every instance of the problem? If it does– prove it, if it does not– f nd an instance with the smallest number of people for which this happens. 1 6. B Averaging down There are q A 1 identical vessels, one of them with Z pints of water and the others empty. You are allowed to perform the following operation: take two of the vessels and split the total amount of water in them equally between them. The object is to achieve a minimum amount of water in the vessel containing all the water in the initial set up by a sequence of such operations. What is the best way to do this? 7. Rumor spreading There are q people, each in possession of a di ¡ erent rumor. They want to share all the rumors with each other by sending electronic messages. Assume that a sender includes all the rumors he or she knows at the time the message is sent and that a message may only have one addressee. Design a greedy algorithm that always yields the minimum number of messages they need to send to guarantee that everyone of them gets all the rumors. 8. Bachet’s problem of weights Find an optimal set of q weights { z 1 > z 2 > ===> z q } so that it would be possible to weigh on a balance scale any integer load in the largest possible range from 1 to Z , provided a. B weights can be put only on the free cup of the scale.weights can be put only on the free cup of the scale....

The perl documentation on sort says this

The comparison function is required to behave. If it returns inconsistent results (sometimes saying $x[1] is less than $x[2] and sometimes saying the opposite, for example) the results are not well-defined.

So it's a bad idea to do that.

ETA: I just did a benchmark. On a 100000 element array, using a FY-shuffle is more than 10 times faster too.