Not getting test case 1 correct, I did shuffle the array but still getting TLE.
Quick Sort Test Case 1 not getting passed
Your code is not working in case of worst case as, For eg, when ur array is completely reversed…
Then The complexity of quicksort will be O(n^2)… So to consider that test case… You need to create a shuffle function… so that you get a random array and then u can simply apply quicksort function to the newly random array obtained…
void shuffle(ll *a,ll s,ll e)
{
ll j;
srand(time(NULL));
for(ll i=e;i>0;i–)
{
j=rand()%(i+1);
swap(a[i],a[j]);
}
}
Hi I am shuffling the array before sorting https://ide.codingblocks.com/s/247667
Please check line 34 and 35
Hi can some one please take a look
Pls make a separate function and then do tht…
Also if ur code still gives TLE, try to update your partition function as :
ll partition(ll * a,int s,int e)
{
ll i =s-1;
ll j=s;
ll pivot=a[e];
for(;j<e;j++)
{
if(a[j]<=pivot)
{
i++;
swap(a[i],a[j]);
}
}
swap(a[i+1],a[e]);
return i+1;
}