Computer Science 1320

Homework Eight

Fall 2009

 

For this homework laboratory assignment we shall write several programs (some of which have already been done or at least partially done in class).

 

Program 1: Write a program that will generate random integers on any interval and write them to a file. Your program must prompt the user for the filename, the lower bound, the upper bound, and the number of numbers desired.

 

Program 2: Write a program that will sort an array of integers using the bubble sort algorithm. Your program must be as efficient as possible, and must count the number of relevant comparisons for efficiency studies.

 

Program 3. Write a program that will sort an array of integers using the maxsort algorithm. Again, you must count the number of comparisons.

 

Program 4. Write a program that will sort an array of integers using the minsort algorithm. Again you must count the number of comparisons.

 

Program 5. Write a program that will sort an array of integers using the insertion sort algorithm. WARNING: I have a very specific way that this algorithm MUST be done: You must write a function that will insert a new element into a sorted array of size k producing a new sorted array of size k+1. This function must then be used to sort an array into ascending order.

 

In each case, your programs must count the number of comparisons required to do their job. You must then decide which algorithm for sorting is the most efficient.

 

Generate the following test data:

Test file 1: a list of 100 integers in sorted order

Test file 2: a list of 100 integers in reverse order

Test file 3: a list of 100 random integers all on the interval [0,9]

Test file 4: a list of 100 random integers all on the interval [0,99]

Test file 5: a list of 100 random integers all on the interval [0,999]

 

Count the number of comparisons for each algorithm on each test file and summarize your results in a spreadsheet.

 

In addition to the usual hand in requirements, You must email me the source code for each of the programs so that I may test your algorithms live. To do this, create a folder called userid8, where userid is your own user id. In this folder, put the source code for each of your algorithms. There are five programs required. Then make a tar archive, attach it to an email and send it to me.

 

You create the archive as follows:

 

tar cvzf <archive to create> <stuff to archive>

 

Specifically:

 

tar cvzf userid8.tgz userid8

 

If I were doing it I would write:

tar cvzf meggen8.tgz meggen8

 

And then send the archive userid8.tgz to me.

 

Homework due date to be announced in class.