Problem TSORT : Time Exceeds

Nope. quicksort won’t. Not mergesort as well, if implemented properly. I used the sort function from the algorithm library which uses the quicksort algorithm for large n and nope, it didn’t give TLE. Dont worry it’ll work!

1 Like

and anyway the time limit of this function in 5 sec. One can blindly vouch for merge sort or quicksort for this case.

Weak test cases probably. I’m sure you won’t get AC here with the above implementations :stuck_out_tongue: SPOJ.com - Problem TSORT

i have already done it on SPOj as well -- and FYI, i got an AC! It works --

Standard Sorting(C++) - 2.39 s
Merge Sort - 3.11 s
Heap Sort - 3.10 s
Count Sort - 2.33 s
Results posted by someone on comments of the same problem on SPOJ.

2 Likes

My bad :slight_smile: Anyway can I see your implementation of Standard sort which was AC on Spoj? What’s the point of solving the question then if you solve with any sorting algorithm (n log n).

Inbuilt Quick Sort in c can get you AC.
Heap sort is also working .
Counting sort is also one option with O(n).
Happy coding.

1 Like

Its right that bubble sort uses too much time for execution.

BUT many have submitted using this sort technique successfully so whats the problem with my code.

Nobody would have used bubble sort, i am sure! If u feel that someone has used bubble sort and still submitted successfully, please comment a link of the solution! Bubble sort can never solve this problem. You atleast require an O(nlogn) technique.

1 Like

bro! If you understood please do accept the answer so that we can close the question :slight_smile:

How do we accept an answer??

There will be a tick symbol down to the vote down symbol.

please view my quicksort code in the bottom…

what should i do??

is still giving TLE in quicksort.

this is the basic quick sort. I mean the naive one! Check for the case when the array is reversely sorted. The time complexity will be O(n^2). So use randomized quick sort. You can even use inbuilt sort function which is implemented using quick sort-sort(arr,arr+n) is the syntax of this inbuilt function. Include algorithm header file

1 Like

@kaushik_iitd i implemented it using mergesort and it got AC. As i told -__- CodeChef: Practical coding for everyone

You can view above quicksort submitted by me…i dont think there is any slow i/o method and its still giving TLE.

Fine… let me check

Please accept an answer so that we can close this question.