Homework 1

Short Description:

Continue to explore algorithms to extract the kth item.

This assignment is worth 15 points.

Goals

When you finish this homework, you should:

Formal Description

Write a program that implements algorithm 2 from the notes. Perform a timing analysis on this program similar to the one done in the notes.

Next you should implement the following algorithm:

FindItemK(A,n,k)
  1. for i<-0 to k-1 do
  2. position = FindPositionOfMinimum(A,i, n)
  3. exchange(A[i], A[position])
  4. return A[k-1]
Perform a similar timing analysis on this algorithms.

Finally, recompile your programs on cslab103 and redo your timing experiments on one of the algorithms.

When you are finished produce a report summarizing your results. This report should be produced using a word processor, and contain the following sections:

Input

The size of the array and the item to find.

Output

The time spent in the algorithm.

Discussion

If you don't understand how to do any portion of this assignment, make sure you ask for assistance. Makefiles and tar are a standard part of most projects in the unix world. They are not hard to use and I will be more than happy to help you with them.

Required Files

Your code, a README file , and a Makefile.

The README file should contain personal information (your name, email, ...) as well as a description of the assignment. It should discuss the algorithms and data structures you employed in accomplishing the assignment. You should also discuss any unique features contained in your program, problems with the program, and special instructions for compiling or using your program. If you wish to provide feedback on the assignment, ask questions, or compose poetry, this is probably the place to do it.

Your makefile for this program should be derived from the following Makefile. To use this file, you should name your program alg2.C. To use this makefile, simply type make and your program should compile. By typing make clean your executables and object files will be removed. If you wish to see what commands make will issue when run you can type make -n. You can edit a make file with any editor. The file should be called Makefile with an uppercase M.

Extra Credit

You may receive up to five points extra credit for implementing and testing any other algorithm to find the kth item. One such algorithm might involve examining k and if it is less than n/2 search for the kth smallest, otherwise search for the n-kth largest.

Remember, if you search the net, or a book for an algorithm, you must document the source.

Submission

This assignment is due Sept 11 at class time. You should email a tar file of your homework directory to dbennett@edinboro.edu. Furthermore you should submit, before class begins, a hardcopy of your lab report.

To create a tar file, you should place all of the files you want to submit into a single directory, for example hw1. One level above this directory type the command:

tar cvzf hw1.tgz hw1
This will create the file hw1.tgz in the current working directory. To check the contents of this file, type :
tar tzf hw1.tgz
To extract the contents of this file, type:
tar xvzf hw1.tgz

Tar is the Tape Archive utility for unix. It was originally intended to copy a file system to the tape device.