Jump to content

Sorting issue

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Wintermute

Wintermute

    Newbie

  • Members
  • Pip
  • 4 posts
Greetings to all. I am trying to make a quicksort that is faster than the qsort function from the library. So far, I've come to discover that if I choose the pivot at the middle of the sorting vector, my qsort beats the library qsort, but this depends on the size of the vector. At 100k elements, it's ok, but at 1kk elements, from 100 test cases, the library beast my version 100-0.
So the problem is at larger vectors, and in choosing the proper pivot. Can somebody please give me some hints? I would very much appreciate it.
I can provide the code I have so far if it's needed.

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
I suppose you could check the vector's size and then call whichever sort fits best for that size.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
Wintermute

Wintermute

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks for the reply, but I know that I can do that if I want to. I just want to make a qsort version that beats the library one, but not by integrating any other kind of sort, just by improving the method of choosing the pivot, or maybe something regarding the sorting vector, but I have ran out of ideas.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You can look at using a hash sort, but you're likely to find that the standard library's qsort has already been highly optimized for a variety of types of data.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Wintermute

Wintermute

    Newbie

  • Members
  • Pip
  • 4 posts
As a type of data, just take in consideration the integer, maybe double. Looking for any other solutions and thanks for the ones so far.

#6
Wintermute

Wintermute

    Newbie

  • Members
  • Pip
  • 4 posts
No more thoughts on this? :(




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users