Chat with us, powered by LiveChat to implement a few sorting algorithms | WriteDemy

Question Description

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.

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order