Sale!

COMPSCI 2XCC3 Lab 3 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (6 votes)

Quicksort [100%]
I am assuming you have seen quicksort in your other courses, having talked to the two 2C03
professors, this should be the case. Otherwise, do some independent research on what quicksort
is. Understanding how it works is relatively straight forward.
In-Place Version [20%]
See the lab3.py file given on Avenue alongside this document. Here I have written a reasonable/traditional implementation of quicksort, called my_quicksort(). Write an “in-place”
version of quicksort. Name this function quicksort_inplace() and include it in your
sorts.py file. Your implementation should take in a list as input, and after terminating
the list should be sorted. By in place it is meant that you only use the input list to
store and move values. You should not be creating copies of the list, or creating other temporary lists. If you do, your implementation is not in-place and therefore will not receive grades.
Before testing the performance of your implementation, discuss any advantages it has over
the implementation you are given. Now design and run some timing experiments (focus on
average runtime here). You may wish to use the create_random_list() function here. Which
implementation is better? By how much? Which would you use in practice?
Multi-Pivot [40%]
As you know, the traditional quicksort algorithm chooses a single pivot and “splits” the
list/array into two components. Why can’t we choose two pivots and split the list/array into
three components? Well, we can. So let’s do it. Implement a dual_pivot_quicksort()
function in your sort.py file. Implement it in the style of my_quicksort() (so we can compare
them later). Now implement a quicksort with three pivots, and (yes, you guessed it) one
with four pivots. In your sort.py file name these functions tri_pivot_quicksort() and
quad_pivot_quicksort().
Design experiments to test the performance of all four quicksort variants (1, 2, 3 and 4 pivots).
Focus on general average case performance. Which of the four variants do you recommend?
For the remainder of the lab, use your recommendation for your default quicksort,
Worstcase Performance [20%]
What is the worst-case performance of quicksort? Run an experiment which graphs the average case performance vs the worst case performance vs n. We saw in lecture (and I have
included it in lab3.py), a function which creates near-sorted-list based off some input factor.
In lecture we also saw implementations/optimizations for three elementary sorts: bubble, selections, and insertion. When this factor is low, i.e. the list is close to sorted, what elementary
sorts/optimization (if any) would you expect to out perform your quicksort implementation?
3 COMPSCI 2XCC3
Design some experiment to explore this further. Focus your experiments on lists of length 1000.
Graphs the runtime of your quicksort as well as a few of the best performing elementary sorts
vs the near-sorted factor. At what value(s) of this factor does quicksort begin to out perform
the other sorting algorithms (if it does at all)?
Small Lists [20%]
Revisit the performance of your quicksort implementation, but focus on small lists, i.e. low
values of n. Compare this to the other (elementary) sorting algorithms. What observations
do you make? Implement a version of quicksort which is optimized using the lessons learned
in this lab. Your implementation may be a hybrid of several sorting algorithms, but it should
fundamentally have elements of quicksort present. Name this sort final_sort() in your sort.py
file. Discuss all design decisions you made and why. What goals were you trying to achieve?
Minimized average runtime? Recursion depth? Worstcase? Some combination thereof? There
is no perfect sorting algorithm, but your reasoning and justification must be valid.