Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this question is on computer algorithm class. Please answer this asap and make s

ID: 3729760 • Letter: T

Question


this question is on computer algorithm class. Please answer this asap and make sure your answer is correct and I promise to give you a thumbs up

12 points apiece. Answer 6 out of 7 questions. No extra credit. 1) Shown below is supposed to be the code for randomized Quick Sort, called Ra written incorrectly. The code is actually that for non-randomized QuickSort. is printed triple spaced to allow you room for your corrections.) ort, called RandQuickSort(), except that it is rt. Make all necessary corrections. The initial call is RandQuickSort( A, 1, A.length ) RandQuickSorti A, p, r) if pcr RandPartition( A, p, r ) QuickSort( A, p, q-1) QuickSort( A, q+1, r) RandPartition( A, p, r) i p-1 for j p to r-1 i=i+1 exchange A[i ] with A[j ] exchange Al i+1] with Al r] return i+1 ge 1

Explanation / Answer

int random_partition(int* arr, int start, int end) { int pivotIdx = start + rand() % (end-start+1); int pivot = arr[pivotIdx]; swap(arr[pivotIdx], arr[end]); // move pivot element to the end pivotIdx = end; int i = start -1; for(int j=start; j