to implement a few sorting algorithms

DO YOU KNOW WHY YOUR FRIENDS ARE POSTING BETTER GRADES THAN YOU? — THEY ARE PROBABLY USING OUR WRITING SERVICES. Place your order and get a quality paper today. Take advantage of our current 15% discount by using the coupon code WELCOME15.


Order a Similar Paper Order a Different Paper

For this micro assignment, you must implement the following sorting algorithms:

Insertion Sort

Mergesort

Quicksort


The sorts you implement each reside in their own files: instrumentedInsertionSort.h, instrumentedMergeSort.h. and instrumentedQuickSort.h. You’ll note that the interface provided takes both the vector to be sorted and a pointer to a stats structure. Please look at the bubblesort implementation carefully to see how the stats structure is used. The reason this is an instrumented sort assignment is the primary focus centers around counting how many times the different sorting algorithms compare values in the vectors and how many moves/swaps happen during the sort.

In the BS algorithm, I put a ++stats.compares before the actual comparison in the for loop. This will count the number of times we do comparisons. If you postincrement in that code you’ll get bugs in your algorithms, mostly due to off by one errors and possible div/0 instances. Preincrement is the right way to go here.

Then, since BS does swaps, I count the number of swaps. You could argue that I should count each stage of the swap (a->tmp, b->a, tmp->b), but a single count for the whole swap is reasonable. The other algorithms should all be counting moves, but BS still comes out way slow no matter which way you do it.

I have tested this code on the EECS SSH servers. I used the command line:

g++ -g -Wall -std=c++11 main.cpp

You can run this with ‘make’, ‘make test’, and ‘make run’ as per usual

There’s an additional test ‘make bigtest’ that’ll do arrays of 30,000 elements. It takes about a minute on my desktop machine and 47 seconds on SSH3 to run and gives some nice big numbers to mull over. 30,000 elements isn’t really that many in a data set, but have a look at the quantity of compares BS does vs. the other sorts! I’ve put a screenshot of the results from my implementation at the end of this assignment description, so you can see the rough numbers you’ll get. Depending upon your implementations, these numbers might vary, so don’t assume you’ll get exactly the same values.

It currently builds and runs properly, but Insertion, Merge, and Quick sort all fail their tests because they’re stubbed in code. I would encourage you to see how I’m generating the testVectors. They’re classes that inherit from vector. The shuffled ones allow you to set the random seed, so you can get the same results each time, or get truly shuffled sets if you don’t set the seed when you instantiate the object. I also use a templated *function* in main for the testing. You can use templates to define the variable types within a function as well as a class. I use it to pick the type of sorted data I want to run the tests on. Lastly, each sorting algorithm has code to time how long the actual sorting takes to complete. Your sort should go between these two clock() calls, be it a function or just the full sorting code for the given algorithm.

Do you require writing assistance from our best tutors to complete this or any other assignment? Please go ahead and place your order with us and enjoy amazing discounts.


Order a Similar Paper Order a Different Paper