Data Structures and Algorithms - Homework 4 | CSCE 310, Assignments of Algorithms and Programming

Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-23v
koofers-user-23v 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 310 Homework4 Spring 2009
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 typeset your homework using L
A
T
E
X 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 in-
cluding 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/Documentation 10
Analysis 10
Total 100
pf3

Partial preview of the text

Download Data Structures and Algorithms - Homework 4 | CSCE 310 and more Assignments Algorithms and Programming in PDF only on Docsity!

CSE 310 Homework4 Spring 2009

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 typeset 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 in- cluding 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/Documentation 10 Analysis 10 Total 100

Program

Implement two advanced sorting algorithms: heapsort and insertion sort and investigate their perfor- mance 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 com- pare 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 102 103 · · · 106 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 102 103 · · · 106 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 102 103 · · · 106 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

Your program must be written in C++, execute correctly on the CSE unix environment, and compile using the g++ compiler using a makefile. The makefile should compile your program into an exe- cutable called SortTest.