

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Spring 2009;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Due 9:30AM Monday, April 13 Name: Student ID: Instructions Follow instructions carefully, failure to do so will result in points being deducted. It is highly recommended that you write your homework using LATEX or Word. Staple this cover page to the front of your assignment for easier grading. Be sure to submit a hardcopy of your problem answers and your program analysis in class. Clearly label each problem and submit the answers in order. Put your program analysis to the end. In addition, submit your homework including the problem answers, all the program files and the program analysis via the webhandin (http://www.cse.unl.edu/~cse310/handin). Late homework policy specified in course syllabus will be strictly followed. Be sure to show sufficient work to justify your answer(s). Numerical and yes/no answers with no explanation will NOT be granted full points. If you are asked to prove something, you must give as formal, rigorous, and complete proof as possible. You are to work individually, and all work should be your own. The CSE academic dishonesty policy is in effect (http://cse.unl.edu/undergrads/academic integrity.php). Problem Page Points Score 5.6.2 194 8 5.6.3 194 10 5.6.11 195 10 6.3.2 (b) 222 6 6.3.9 223 6 6.4.5 230 20 Program Correctness 20 Style/Doc 10 Analysis 10 Total 100
Implement two sorting algorithms heapsort and insertion sort and investigate their performance on arrays of sizes n = 10^2 , 10^3 , 10^4 , 10^5 and 10^6. For each of these sizes, consider a. randomly generated files of integers in the range [1..n]. b. increasing files of integers 1, 2, …, n. c. decreasing files of integers n, n-1, …, 1. The HeapSort.cpp and InsertionSort.cpp source files include the implementation of the two algorithms. In addition, you need to create a main.cpp file to do the empirical tests on your algorithms. To compare and contrast the two algorithms you will need to keep track of how many comparisons, swaps, and CPU time (see clock()) it takes for each instance to be sorted by each algorithm. For case a, you may want to run multiple randomly generated instances of n and take an average, the choice is yours. To report the final results, the main program should output a nice looking table. The following is merely a suggestion. As long as it is readable and conveys all the necessary information you may design your own table. Case a: Randomly Generated Files n | 10^2 | 10^3 | ... | 10^6
HeapSort | comps: 32.5 | comps: xx | ... | comps: xx | swaps: 4.3 | swaps: xx | ... | swaps: xx | time: xx | time: xx | ... | time: xx
InsertionSort | comps: 32.5 | comps: xx | ... | comps: xx | swaps: 4.3 | swaps: xx | ... | swaps: xx | time: xx | time: xx | ... | time: xx
Case b: Increasing Files n | 10^2 | 10^3 | ... | 10^6
HeapSort | comps: 32.5 | comps: xx | ... | comps: xx | swaps: 4.3 | swaps: xx | ... | swaps: xx | time: xx | time: xx | ... | time: xx
InsertionSort | comps: 32.5 | comps: xx | ... | comps: xx | swaps: 4.3 | swaps: xx | ... | swaps: xx | time: xx | time: xx | ... | time: xx
Case c: Decreasing Files n | 10^2 | 10^3 | ... | 10^6