Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following sort void sortRec(std::vector & A, int n) { if (n==1) return; sortRec(A, n - 1); int i; int tmp =A[n-1]; i=n-1;

   

Given the following sort void sortRec(std::vector & A, int n) { if (n==1) return; sortRec(A, n - 1); int i; int tmp =A[n-1]; i=n-1; while (i>0&& A[i-1] >tmp) { } A[i] =A[i-1]; I- A[i] = tmp; } Modify the function so the number of comparisons are counted the part of the code that is in yellow Write a program that will Generate 3 vectors for an inputted size One vector for the best case One vector for the worst case o One vector for the average case For the best and worst case vector only run the sort once to get the count (that matters is the order of the starting vectors) For the average case you will have to run the sort serval times(100) on different ordered values in the vector and calculate the average number of comparisons Once you have all your counts for the three cases print them. For size n Number of comparisons for best case is x Number of comparisons for worst case is y Number of comparisons for average case is z

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_2

Step: 3

blur-text-image_3

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

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

More Books

Students also viewed these Programming questions

Question

discuss ways of measuring sickness absence and sickness presence;

Answered: 1 week ago

Question

Why is multicultural education for all?

Answered: 1 week ago