
Sorting
1. Add a counter to the functions insertionSort and mergeSort that counts the number of comparisons that are made. Run two functions with arrays of various sizes. At what size does the difference in the number of comparisons between significant? How does this size that the orders of these algorithms predict? Compare your analysis with the actual running times and counter as a function of the input size n = 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 8192, 16384 <time.h> and clock() function.) Use the below code to generate an array value for testing.
for (int i = 0; i < n; i++)
{
//Create an unsorted array
arr[i] = (double)(n - i);
}


Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 6 images

- Python Programming Elon Musk sees the beauty of an array as the maximal value of gcd(A,A+1,..,A;).(r-I+1) over all the subsegments [1,r] of the array A. aside from the beauty of the initial array, he wants to know the beauty of the array after performing each of Q updates. Each update replaces a subsegment of the array with an arithmetic progression. Updates are cumulative, in each update you are given four integers I, r, x, and y. Then for each ie[I,r], you must replace Ai with x+y(i-I). Input Output 1 12 65 18 264 10 9 12 14 45 12 6 18 2524 19 2663 24 1573 1640arrow_forwardIllustrate the execution of the selection-sort algorithm on the following input sequence: (12, 5, 36, 44, 10, 2, 7, 13, 22, 23)arrow_forwardAnswer the question using bubble sort, enhanced bubble sort, selection sort, and insertion sort. Milo only needs the 10 highest exam scores in an array of several hundred scores. Which sort should he use that can easily be modified to accomplish the task and why?arrow_forward
- 5. In Quick Sort algorithm, what are the key differences in performance characteristics when comparing the use of a fixed pivot (such as always choosing the first or last element) versus a pivot chosen randomly or through a median-of-three approach?arrow_forward2. Suppose the function MergeSort( Vis a recursive implementation of the merge sort algorithm, which takes as input an integer array A. How many times is MergeSort( ) recursively called, if A is of size n? Answer: Select T Select Olnlogn 3. How many times is the Merge routine called in total, O(1) Oln 2) nswer. ISelect ]arrow_forwardapply perceptron algorithm to a data set by hand.arrow_forward
- Create and test predictions regarding the insertion sort and selection sort running times for arrays with just two key values, assuming that the values are equally likely to occur.arrow_forwardCompare the sorting durations of the insertion sort and QuickSort using a tiny array (less than 20). What is the time difference? Could you clarify why? Compare the sorting durations of the insertion sort and QuickSort using a tiny array (less than 20). What is the time difference? Could you clarify why?Compare the sorting durations of the insertion sort and QuickSort using a tiny array (less than 20). What is the time difference? Could you clarify why?arrow_forwardWhat strategies can you use to distinguish between fake andfactual information on the internet?arrow_forward
- 3 illustrates the counting sort algorithm. For simplicity ofimplementation and understanding, the range (a, b) within which the unordered setof keys lie is assumed to be within (0, k).arrow_forwardCreate and test assumptions regarding the running times of insertion sort and selection sort for arrays with just two key values, assuming the values are equally likely to occur.arrow_forwardCompare the sorting times of the insertion sort with QuickSort using a small array (less than 20). What is the time difference? Could you explain why?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





