Question: Consider the following algorithm given in Java code: 1 . public class Sort { 2 . public static void sort ( int [ ] array,
Consider the following algorithm given in Java code:
public class Sort
public static void sortint array, int low, int high
if low high
Find pivot element such that element smaller than pivot are on the left
Element greater than pivot are on the right
int pivotIndex partitionarray low, high;
Recursively sort elements before and after partition
sortarray low, pivotIndex ;
sortarray pivotIndex high;
private static int partitionint array, int low, int high
int pivot arrayhigh;
int i low ;
for int j low; j high; j
if arrayj pivot
i;
int temp arrayi;
arrayi arrayj;
arrayj temp;
int temp arrayi ;
arrayi arrayhigh;
arrayhigh temp;
return i ;
Note: Always give the tightest upper bound possible when giving the BigO For example, if you can
prove that is and that is only choose the tighter upper bound, ie is
a pts Give a BigO for the worstcase running time of this algorithm for an input array of
length Explain how you obtained this worst case.
b pts Give a BigOmega for the bestcase running time of this algorithm for an input
array of length Explain the type of inputs sample inputs that will produce this best case.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
