Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in C++ Sorting Benchmarks Write a program that generates and sorts an array of a user-specified number (arraySize) of randomly generated numbers. To keep

write in C++

Sorting Benchmarks

Write a program that generates and sorts an array of a user-specified number (arraySize) of randomly generated numbers. To keep the values to a reasonable range by using the array size as the upper bound for the random numbers (between 1 and arraySize). Your program should call the individual functions that implement the five sorting algorithms discussed in class (see the lecture slides). Each function should keep a count of the number of comparisons/exchanges it makes. Display the pre-sorted array, the sorted array, and the number of comparisons for each algorithm.

Note: In this assignment, you will compare all the five sorting algorithms from the lecture notes (brute force sort, bubble sort, bubble sort++, selection sort, and insertion sort) with each other using the same data for each. Start with getting one to work first. The idea is that once you have one, adding in the other algorithms is relatively simple. Hint: use the algorithms from the slides! Your program MUST include a function for each algorithm and use them appropriately. The main procedural code must first prompt the user for the arraySize = number of elements to store in the array ("How many elements in the array?"). Then, it will generate arraySize random integers between 1 and arraySize (the number they entered--yes, you will use it twice!). Since each function will sort the array, changing the values, you will need to make multiple copies of the generated array to test the same numbers against each algorithm. Each algorithm will return the number of comparisons made. This is when one element is compared to another, regardless of whether or not they get swapped.

You will need to include at least these functions: void displayArray(int values[], int size); int bruteForceSort(int values[], int size); int bubbleSort(int values[], int size); int bubblePPSort(int values[], int size); int selectionSort(int values[], int size); int insertionSort(int values[], int size); The output should look something like this: How many elements in the array? 20 BRUTE FORCE SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 400 BUBBLE SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 190 BUBBLE SORT PLUS PLUS Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 184 SELECTION SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 206 INSERTION SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 186

Compile, run, and test your program. Make sure there are no errors and it functions properly. You can hit F5 to compile and run the program. Your program must run without errors to get full credit! Upload (attach!) your cpp file here for grading. It must be named correctly and saved as a readable cpp file with the proper extension.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

What purpose do disability models serve?

Answered: 1 week ago