Design and Analysis of Algorithms

CSE 5311 Section 087/088/098 Fall 2002

Program 2

Due: October 24, 2002 (midnight)

For this assignment you will write a program to compare three different algorithms for solving the activity selection problem described in Chapter 16 of the textbook. The three algorithms are exhaustive, dynamic programming, and greedy algorithm. Your program will generate activity selection problems of various sizes, measure the running time of each algorithm on the problems, and plot the running times of each algorithm as a function of the problem size. The specifics of the program follow. All code must be written by you individually and may not be copied in whole or in part from other sources.

  1. First, you will implement code to randomly-generate activity selection problems of a certain size n. The start and finish times should be randomly drawn from the range [0,100] while ensuring that the start time of an activity is less than or equal to its finish time.

  2. The three algorithms should take as input the set of activities defined by their start and finish times, sorted in increasing order by finish time. You can just sort the activities once and pass the sorted activities to each of the three algorithms. Each algorithm should return a maximum-sized set of mutually compatible activities. Also, you should measure the amount of time spent in each algorithm.

  3. The exhaustive algorithm should examine every possible subset of activities to find the maximum-sized set. The dynamic programming algorithm is based on computing mi iteratively for i = 1, 2, ..., n, where mi is the size of the largest set of mutually compatible activities among activities {1, 2, ..., i}. The greedy algorithm should follow the pseudocode given in Chapter 16.

  4. The main part of your program should, for each size n = 1 to 30, generate three different activity selection problems of size n, which are sorted and then input to each of the three algorithms. For each generated problem your program should output n, the sorted set of activities, and the solution and running time for each algorithm. Finally, your program should output the average time over the three runs for each algorithm and each value of n.

  5. Along with your program, you should also submit a nicely-formatted plot of your results. The plot should show three curves, one for each algorithm, plotting the average running time of the algorithm on the three generated problems versus the problem size n.

  6. After ensuring that your program compiles and runs correctly on the omega.uta.edu system, submit your source code and plot to me (holder@cse.uta.edu) by the above deadline. Please only send one email message; use attachments if sending multiple files. In addition to correct functionality and satisfaction of the above constraints, your submission will be graded based on good programming style and documentation.