|
The programs that you turn in will be graded according to the criteria given in the first of the following two links. The second link gives detailed instructions on exactly how you are to turn in your finished assignments.
Program grading criteria
Turning in your assignments
Below are your homework assignments. The due date for each one is contained in the assignment description.
- Assignment 7
- This assignment is not a programming assignment. You can either write up your solutions using pen and paper or you can produce an electronic document using programs like MS Word, LaTeX, or Maple. Whatever you turn in should be neat, readable, and well organized. The problems for this assignment are in this handout. This assignment is due Friday, December 6.
-
- Assignment 6
- This assignment is not a programming assignment. You can either write up your solutions using pen and paper or you can produce an electronic document using programs like MS Word, LaTeX, or Maple. Whatever you turn in should be neat, readable, and well organized. The problems for this assignment are in this handout. This assignment is due Friday, November 22.
-
- Assignment 5
- This assignment is not a programming assignment. You can either write up your solutions using pen and paper or you can produce an electronic document using programs like MS Word, LaTeX, or Maple. Whatever you turn in should be neat, readable, and well organized. The problems for this assignment are in this handout. This assignment is due Friday, November 8.
-
- Assignment 4
- This assignment is not a programming assignment. You can either write up your solutions to these problems using pen and paper or you can produce an electronic document using programs like MS Word, LaTeX, or Maple. Whatever you turn in should be neat, readable, and well organized. Do the following problem at the end of Chapter 1 from the course textbook (page 25).
Do the following problems at the end of Chapter 2 from the course textbook (pages 50-51).
- Problem 2-2.
- Problem 2-5.
- Problem 2-6.
This assignment is due on Friday, October 18.
- Assignment 3
- For this assignment you will use your four implementations of sorting algorithms from the last assignment to empirically show that the algorithms have running times that grow as we stated in class.
Write a C or C++ program that runs your four sorting algorithms on random arrays with a range of sizes. Your program should gather statistics on how long each algorithm runs for each array size. Your program should output its statistics in a reasonably formatted manner. Cut and paste your program's output into a text file and give an explanation of why your data shows that selection and insertion sort are O(n^2) algorithms and merge sort is an O(n*ln(n)) algorithm.
Your data for merge sort should go up to at least an array size of 4,194,304 integers.
In addition, gather statistics on the running time of your algorithms on sorted arrays. Your data should show that selection sort is still O(n^2) and merge sort is still O(n*ln(n)) for arrays that are already sorted, but insertion sort is O(n) for sorted arrays. How do the running times for selection sort and merge sort compare for sorted vs. random arrays? Do either of these two algorithms show any speed up for sorted arrays? Explain why or why not. Your statistics on sorted arrays should be displayed and explained separately from the statistics on random arrays.
To get data on how long a sorting algorithm runs on a particular array, use the Win32 function GetTickCount() . To use this function, your will need an include statement at the beginning of your program:
#include <windows.h>
You time the execution of a function like this:
int time0 = GetTickCount();
sort(myArray,0,n); // function to be timed
int executionTime = GetTickCount() - time0;
Turn in a zip file containing your implementations of the sorting algorithms, your program that gathers and outputs the statistics, and the text file explaining your results. This assignment is due Wednesday, October 2.
- Assignment 2.
- For this assignment you are to implement, in either C, C++, or Java, several sorting algorithms.
- Write a function that implements the selection sort algorithm.
- Write a function that implements the insertion sort algorithm.
- Write a function that implements insertion sort recursively (see Exercise 1.3-4, page 15, from the algorithms book that is on reserve in the library).
- Implement merge sort (you should write two functions, a recursive
mergeSort() function and a merge() function, as described on pages 12-13 of the algorithms book on reserve in the library).
Write a main() function that tests your sorting functions. You will need data to sort. The following file contains a function that creates an integer array and fills it with a random permutation. This function can be used, as is, in a C or C++ program.
permutation.h
Test your sorting functions with arrays of size less than 100 (so that you can print out the arrays before and after sorting, to see that your functions work). In the next assignment, we will "benchmark" these implementations, to see if they run as our analysis of them predicts.
Organize your code in whatever way you think is best. Put all of your code in a zip file and e-mail me the zip file. This assignment is due Wednesday, September 18.
- Assignment 1.
- Download the following header file and four program files, which are written in C.
permutation.h
permutation1.c
permutation2.c
permutation3.c
permutation4.c
The four C programs all include the header file, which contains code that is common to all four programs. The four C programs all do exactly the same thing, i.e. they solve the same problem, but they do it in completely different ways, i.e., they each use a different algorithm. The C program files each define a function
permutation() that fills an array of size n with a random permutation of the integers from 1 to n. Each C file has a different implementation of permutation() .
Your assignment is to analyze the four implementations of permutation() and document your analysis in the four C programs. Which of the four programs is the fastest? Which is the slowest? What makes the fastest one faster than the others and what makes the slowest one slow? How much faster is the fastest one than the slowest one? For each program, how long it runs depends on the size of the permutation being computed; how does each program's execution time depend on the size of the permutation? For what size permutation does each program become impractical to run? Your answers should be specific. Try to really figure out what is going on in each implementation of permutation() .
You will turn in to me the four C programs with your analysis of each one contained in comments in the C code (you can ignore the header file; you do not need to even look at it). Put the four files in a zip file and email me the zip file as per the homework instructions.
This is due Monday, September 9. Since this is a small class, after you have turned in your explanations I will ask each of you to meet with me so that you can explain your results to me.
|
|