Question

Given a set P of n teams, a round robin tournament is a collection of games...

Given a set P of n teams, a round robin tournament is a collection of games where every team plays each other team exactly once. Design an efficient algorithm for constructing the schedule of games of a round robin tournament for the n teams. Prove your algorithm correctly creates the round robin tournament, and state and justify its running time.

Homework Answers

Answer #1
def roundRobin(units, sets=None):
    """ Generates a schedule of "fair" pairings from a list of units """
    if len(units) % 2:
        units.append(None)
    count    = len(units)
    sets     = sets or (count - 1)
    half     = count / 2
    schedule = []
    for turn in range(sets):
        pairings = []
        for i in range(half):
            pairings.append(units[i], units[count-i-1])
        units.insert(1, units.pop())
        schedule.append(pairings)
    return schedule

""" test code """
if __name__ == '__main__':
    for pairings in roundRobin(range(5)):
        print pairings
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions