https://ide.codingblocks.com/s/203738 is the code that i have written please help it is showing tle in one of the test cases.
Showing time line exceeded
Yes, as given in the given Use randomized quicksort, otherwise worst case will not pass.
Randomized quicksort just decreases the chances of happening the worst case which will be O(n^2).
For randomized quicksort, you just have to replace your end index element with some random index element which can be done using rand() function in c++.
To generate a random index:-
int random_index = start + rand()%(end-start);
here rand() function return any random integer between 0 and INT_MAX, so for scaling it between start and end we can do this.
Check it by adding this line, it will surely give WA.
Hope it helps.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.