

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Algorithms and Data Structures; Subject: Computer Science & Engineering; University: Michigan State University; Term: Spring 2009;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Due by 11:59 PM Friday 23 January 2009 (100 points total)
This color indicates recent changes since the homework was first released. In this case, these are just additional comments in response to some questions that may be of assistance to you. You do not need to redo problem 1 if you already did it and did not create a random vector this way, so long as you created some kind of test vector.
Submit via http://www.cse.msu.edu/handin/ 3 files:
Do the following problems from Chapters 1 and 2 of our text. We do not want just the âanswersâ (such as true or false or 5N 2 ); we want the reasoning behind the answers. Additionally, take a look at the homework submission guidelines on the course webpage and use those as a general formatting guide.
(a) Make a table that shows the runtime for each of the 3 algorithms on sequences of length N=100, 200, 400, 800, 1600, 3200, 6400. To test these functions create a random vector that has alternating positive and negative numbers. This creates a problem that is interestingâ if they are all positive, then the maximum subset problem is trivialâ the entire set is the best subset. Just try to use the same set (e.g. use the same seed) to get a decent benchmark. Do not worry too much about random variationâ this will not disguise the underlying trends. We suggest you use random numbers in between -100 and
...
// Use the same seed every time so the same random vector is // generated. Call this once. srand(1000);
... // fill up the random vector with alternating positive and // negative values for(int count=0;count<size;count+=2) { randvector[count] = rand() % 100; } for(int count=1;count<size;count+=2) { randvector[count] = - (rand() % 100); }
Note that algorithm 1 will be very slow for large values of N. If it is taking a very long time to complete (say, more than ten minutes), you may comment out the call to algorithm 1 and time the other two algorithms instead. Algorithm 4 is very fast. If it completes in zero seconds when you run it, you will need to test it with larger values of N (e.g. N=12800, 25600, etc.) until you start to get actual results. You may want to comment out the calls to algorithms 1 and 2 when you do this. ( points)
(b) Give an argument for the complexity of each algorithm, using the ratios of runtime as the sequence size N is doubled. (10 points) (c) Change each of the 3 functions by instrumenting them as follows.