Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 5. Show execution of Select on the given vector A of integers. Follow lecture slides format (assume that sorting of 5-integer groups is done
Problem 5. Show execution of Select on the given vector A of integers. Follow lecture slides format (assume that sorting of 5-integer groups is done in-place, i.e. inside the vector). Show recursive calls in the order of their execution (show only recursive calls at line 15 or 17). For each recursive call, show the following: 1) low, high 2) vector medians filled in with medians of 5-integer sub-ranges of A 3) pivot (the median of the medians) 4) Range A[low, high) after partition at line 11 (before doing partition, swap pivot with A[high]) 5) p 1 int selection (vector A, int low, int high, int k) { 2 if (size 35) 3 insertion (A, low, high); //sort the range return A[k]; vector medians; 6 For each 5-integer sub-range of A do: sort the sub-range using insertion in place push back the median of the sub-range to medians 9 pivot = selection (medians, 0, medians.size - 1, medians.size/2) 10 pivotIndex = findPivot (A, pivot)//scan A return index of pivot 11 p = partition (A, low, high, pivotIndex) 12 if (k == p) 13 return A[p] 14 else if (k
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started