Docsity

CSE 310 Homework 2: QuickSort and Partition Algorithms, Assignments of Algorithms and Programming

Toggle sidebar
bg1
CSE 310 Homework2 Spring 2009
Due 9:30AM Wednesday, March 4
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
2.4.9 77 10
3.3.2 112 10
3.3.4 112 10
4.2.9 135 10
4.3.6 139 10
Program
Correctness 25
Style/Doc 10
Analysis 15
Total 100
pf3

Partial preview of the text

Download CSE 310 Homework 2: QuickSort and Partition Algorithms and more Assignments Algorithms and Programming in PDF only on Docsity!

CSE 310 Homework2 Spring 2009

Due 9:30AM Wednesday, March 4 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 2.4.9 77 10 3.3.2 112 10 3.3.4 112 10 4.2.9 135 10 4.3.6 139 10 Program Correctness 25 Style/Doc 10 Analysis 15 Total 100

Program

The goal of this programming assignment is to implement QuickSort and several Partition algorithms using different criteria for choosing the pivot element. You will then establish testing parameters and empirically test each partition algorithm against each other. Specifically, you will implement the following pivot choice criteria:

  • The first element
  • Median-of-Three
  • Random pivot choice (use rand() to get a random index)
  • Your own pivot criteria (be sure to detail your choice and justification in your write-up) You will only be sorting integer arrays. Your QuickSort.cpp source file will include the following four separate implementations:
  • QuickSort_First
  • QuickSort_MedianofThree
  • QuickSort_Random
  • QuickSort_XX In addition, you need to create a main.cpp file to do some empirical tests on your algorithms. First, you will analyze each algorithm on randomly generated instances of various array sizes. You can choose your own test sample sizes if you wish but be sure to justify your choices in your analysis. A good suggestion would be n = 1000, 5000, 10000, 15000,... 5*10^6. As is often the case in life, more is always better, and diversity is good (i.e. try different types of random data– small integers, large integers, arrays with no duplicates, etc). See the man pages on "srand()” and "rand()” (use srand(time(NULL)) to seed the random number generator; time is a function in the time.h library) to populate your arrays with random integers. For comparison purpose, you need to ensure that the four QuickSort with different partition algorithms are acting on the same arrays. To compare and contrast the four 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. You may want to run each instance of n a number of times 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. n | 1000 | 15000 | ... | 5000000

QuickSort with | comps: 4332.5 | comps: xx | ... | comps: xx First-Element | swaps: 324.3 | swaps: xx | ... | swaps: xx Partition | time: xx | time: xx | ... | time: xx


QuickSort with | comps: 4332.5 | comps: xx | ... | comps: xx Median-of-Three | swaps: 324.3 | swaps: xx | ... | swaps: xx