Posted: April 5th, 2023

You will investigate different ways to improve the performance of the basic vers

Place your order now for a similar assignment and have exceptional work written by our team of experts, At affordable rates

For This or a Similar Paper Click To Order Now

You will investigate different ways to improve the performance of the basic version of quicksort. You should try at least 3 variations of the quicksort algorithm and record your observations about its performance in a file “Quicksort Report”.
We provide a working basic version of quicksort using the Lomuto Partition algorithm with which you can start. Here are the three variations we want you to try:
1. Typically the base case of quicksort is when the size of the vector to be sorted is at most one. In this case the vector is already sorted. On a vector of size n, the base case will be reached n times. All these function calls on small vectors can be time consuming. Write a function with the signature
void insertionSortBaseCase(vecIter begin, vecIter end);
that does the base case differently. When begin and end define a range that is smaller than some threshold, then sort this range using insertion sort. It is typically suggested that this change sees the most improvement when the threshold for switching to insertion sort is on vectors of size 8-16. Play around with different thresholds and see if you notice improvements over the basic version of quicksort. Record your observations in the file “Quicksort Report”.
2. What is the running time of the basic version of quicksort provided on a vector that is already sorted? Record your answer in the “Quicksort Report”. We will now make a change to improve the running time of quicksort on a vector that is already sorted by implementing “median of 3” pivot selection. In lecture, we always just used the first element in the range as the pivot element. In median of 3 pivot selection we look at the first, middle, and last entries of the vector in the current range and use the element in between the maximum and minimum values of these three as the pivot. Add median of 3 pivot selection to your insertionSortBaseCase function in the function
void median3InsertionSortBaseCase(vecIter begin, vecIter end);
What is the running time of this quicksort with median of 3 pivot selection on a vector that is already sorted? Record your answer in the “Quicksort Report”.
3. We leave the third variation up to you. Try something and see if you can make quicksort faster. You might consider another means of choosing the pivot, perhaps taking the pivot to be a random element in the vector. Or you may look at a different partition algorithm, for example the Hoare Partition algorithm or Dijkstra’s Partition algorithm. For ease of our testing, please give your third variation this function name:
void thirdVariation(vecIter begin, vecIter end);
In the “Quicksort Report” record your observations about this third variation. Does it lead to faster results on any particular kinds of inputs?
Files
I have included 4 files. Your code should be implemented in the quicksort.cpp file. When you hit “mark” we test the three variations on test cases to make sure they correctly sort. I have also provided main.cpp with test cases and some sample examples of how to measure the running times of a sorting variation on different inputs. Finally I have included the Stopwatch class in stopwatch.hpp for you to measure the performance of your algorithms.
Compiling
For this exercise we compile with g++ -std=c++20 -Wall -Wextra -O3. The O3 option tells the compiler to optimise the code as much as it can. It is always a good idea to measure performance with full compiler optimisations enabled.

For This or a Similar Paper Click To Order Now

Expert paper writers are just a few clicks away

Place an order in 3 easy steps. Takes less than 5 mins.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00