code:
Showing timelimit in testcase 1
Hi yash
Read the question carefully : use randomized quick sort for worst case
You only choose last element as pivot but it should be chosen randomly.
for eg: add this function
int partition_r(int arr[], int s, int e)
{
// Generate a random number in between
// sā¦ e
srand(time(NULL));
int random = s + rand() % (e - s);
// Swap A[random] with A[e]
swap(arr[random], arr[e]);
return partition(arr, s, e);
}
call this function from quicksort()
Hope it helps:)