(Latest Revision -- 03/29/00)
03/29/00 -- Revised info on where to get "pivotbis"
03/20/00 -- Added second homework problem.

CS 4440 Work Assignment:
Weeks Five to Six

Assignments for weeks #5-6 of Theory of Algorithms

Reading to be finished by Thursday, 03/30/2000:

* finish chapter 7
* start on chapter 8

##############################
QUIZ:  We need to have a quiz soon.  How about Tuesday, March
28?  We should be able to cover:

* pp. 1-35  (some preliminaries)
* Chapter 3 (asymptotic notation and smoothness.)
* Section 4.7 (solving recurrences -- pp. 116-139
* Section 5.7 (heaps)
* Section 5.9 (disjoint set structures)
* Chapter 6 (greedy algorithms)

##############################
HOMEWORK to be turned in at the start of class 04/04/2000
-----------------------------------------------------------------
Problem #1.

Write a program that implements the algorithm sequence2 of page
214.  (See also my mnemonic work-up of this algorithm: in

http://shalim.csustan.edu/~john/Classes/

under

CS4440_TheoryOfAlgorithms/Notes/Chapter06/6.53.fastAlg.jpg)

INPUT:

Write the program so it reads a list of N deadlines from
standard input.  Assume that the first deadline is for job #1,
the second for job #2, and so on.  Assume also that job #1 is
the one with the most gain, job #2 the one with the next
highest gain, and so on.  If you want to use static memory
allocation, you may assume some simple constant bound like
N<=15.

OUTPUT:

The program must execute the algorithm on the input and write
a report telling what schedule was built corresponding to the
input, and also telling how many jobs were actually included in
the schedule.

ALGORITHM:

You must really implement the particular algorithm referred
to.  In particular, the algorithm must employ one of the
"ultra-efficient" forms of the union-find data structure, and
the overall performance of the algorithm must be theta(N),
worst case.

TESTING:

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

WHAT TO TURN IN:

Neat printouts of the source code and test scripts.  You need
not e-mail anything.

-----------------------------------------------------------------
Problem #2.

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 share discuss it in class.

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.

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:

Neat printouts of the source code and test scripts plus a
typewrittn summary of your findings.  Don't print out the
contents of long input files.  You need not e-mail anything.

-----------------------------------------------------------------