(Latest Revision -- 03/11/2002)

CS 4440 Work Assignment:
Weeks Five to Six

Assignments for weeks #5-6 of Theory of Algorithms


Reading to be finished by Friday, 03/29/2002:


QUIZ:

We need to have a quiz soon. How about Wednesday, 03/27/2002? We should be able to cover:


HOMEWORK

to be turned in at the start of class 03/29/2002

Write a program that implements the final O(n) version of the algorithm "selection" of p238. "Final version" means you need to use function "pseudomed of page 239 instead of function "median" that appears in the call on page 238. Also you will need something for the function "pivotbis." There is a very nice version of this function in the class web space. Its design is inspired by a version of the algorithm that appears in the Carrano text book. I will discuss it in class.

See also

my mnemonic work-up of this algorithm.

INPUT:

Write the program so it will input a file like this:

Number of numbers
number #1
number #2
number #3
number #4
.
.
.
number #N 

and load the numbers into an array. Of course this should be a pseudo-random list of numbers, certainly not sorted. Some of the lists you test should be long lists. I can share with you a program that will generate a long list of pseudo-random numbers, if you like. Let me know if you are interested.

The program should also input from the user, executing a main loop, getting a rank of an item to locate each time through the loop. You can run the program and have it tell you several values for items of various ranks.

TESTING:

Create some nice test inputs and run your program on them.

If you use the unix sort command (sort -n) to sort a copy of each version of the input file (after taking out the first number) then you can use the sorted versions of the file to check the accuracy of your program.

After getting the output from the program, look at the sorted files and see if the values the program found are really in the positions of the sorted file corresponding to the ranks. For example, if the program says that the 50th smallest element of the array is 96593, then you should find 96593 in the 50th position of the sorted list.

WHAT TO TURN IN:

e-mail me a copy of the source code for your program. Turn in a hardcopy of test scripts plus a typewritten summary of your findings. Don't print out the contents of long input files.