PROGRAM #1

Fall 2008

Due: September 24, 2008, 5pm


General Guidelines:


Assignment:

The Josephus problem is the following game: N people, numbered 0 to N-1, are sitting in a circle. Starting at person 0, a hot potato is passed. After M passes, the person holding the hot potato is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the hot potato. The last remaining person wins. Thus, if M=0 and N=5, players are eliminated in order, and player 5 wins. If M=1 and N=5, the order of elimination is 2,4,1,5 before 3 wins.

Your task is to provide two different implementations for the Josephus problem using STL list and vector, respectively. Your program should build upon the following source code:

Using the above source code, implement your own ListJosephus.cpp, VectorJosephus.cpp, and Person.cpp. To test and report on your two implementations, write two test programs called testListJosephus.cpp and testVectorJosephus.cpp. These programs should follow the below test sequence of steps:

  1. Instantiate an object of the corresponding Josephus class with a user-specified N and M;
  2. Play a full game until a winner is found;
  3. Report the elimination sequence and the winner;
  4. Report the following time statistics: i) total time for playing the game, ii) average time spent between two consecutive eliminations. The timing statistics should  be in seconds or milliseconds or microseconds (whichever gives the closest precision to the actual time of the event).

REPORT:

In a separate written document (in Word or PDF), compile sections A through D  as below:

  • A: Problem statement. In a couple of sentences, summarize the goal of the problem.
  • B: Algorithm design. Within one page, provide a brief description of the main ideas behind your algorithms for the two implementations. You can do this in the form of a step-by-step pseudocode (in plain English) along with perhaps figures (if needed).
  • C: Experimental setup. In this section, you should provide a description of your experiment setup, which includes but is not limited to
  • D: Experimental results. In this section, you should compare the performance (running time) of the list and vector implementations, and provide justification for your observations.

    For your testing and reporting, conduct the following two sets of experiments separately for each of your two implementations:

    In your report for the results, address the following points:

  • COVER SHEET:

        Each submission should be accompanied by a cover sheet which is a single page document that contains all the information listed in this sample cover sheet: Word or PDF. Assignments without a cover sheet will NOT be graded.

    CHECKLIST FOR SUBMISSION:

        ___  Cover sheet

        ___  Zipped folder of the source code

        ___  Written report

        ___  All the above three zipped into another folder archive (named after your last name)