Блог пользователя codeDREAMER

Автор codeDREAMER, 13 лет назад, По-английски

Hello everyone..!! Yesterday i was trying to check the time taken by sorting techniques in this simple ques : http://www.codechef.com/problems/TSORT here the time limit is 5 sec and the no. of elements <=10^6 and the elements are <=10^6..as the optimal solution for this is hashing (or linear sorting) in O(n) i was trying to test for other sorting techniques too... and i observed following : 1. Heapsort : time limit exceeded 2. Mergesort : same 3. quicksort as expected same due to O(n^2) worst case 4.sort(a,a+n) in <algorithm.h> :same but the standard library function qsort passed now i can't understand that why qsort which is also qucicksort passed and mine other sorting techniques failed?? Is it that qsort works in different way or something else ... plzz help .. thanx :)

  • Проголосовать: нравится
  • -16
  • Проголосовать: не нравится

»
13 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Remember that quick sort is a randomized algorithm .Here the pivot point which you choose has a very big hand to play . For eg . you can check for a few sample cases that the end element, the start element and the middle element choosen as pivot point have different run times. I dont know exactly how is the qsort implemented in C++ STL , but you can just shuffle your array once to make your own version pass I suppose .

»
13 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Are you sure because i got AC using sort(a,a+n) and scanf printf