Skip to main content
gamedev.net
🔒 Locked

Sorting algorithm

Started by AndrewSmart Jan 9, 2003 at 8:03 AM 4 replies 300+ views
Original Post
AndrewSmart
AndrewSmart
To all maths gurus: If I have a list of integers, and I want to sort the list in numerical order, what is the best (fastest) algorithm to use ? There may be several thousand integers in this list. It will be the basis of primitive sorting in my 3D rendering engine, where I sort the list of primitives based on selected criteria, but it basically comes down to the sorting problem above. I would really appreciate some help to get the fastest solution. Yours hopefully... Andrew
v71
v71
Basically we have bubblesort, quicksort,heapsort,mergesort, selectionsort,insertionsort,radixsort, most of them do the work quite well with a partial ordered array , if i were in you i would stick with quicksort for some reason , the first is hystorical, this is the ''fastest'' sort around , second because you''ll find it over all c++ books since it comes with the libray , but i would check also the radix ( some book call it digital ) sort, do some google around .

LilBudyWizer
LilBudyWizer
Quicksort. Use the STL though. Find the container that best represents what your functional needs are. Actually coding a quicksort is not really a learning experience. It is pretty much find a correct implementation and copy it. It isn''t really an algorithm that can be adapted to purposes other than sorting. Anything along those lines you could gain can be gotten from simply reading a general description of how it works.
Keys to success: Ability, ambition and opportunity.
v71
v71
Quote:
It isn''t really an algorithm (quicksort) that can be adapted to purposes other than sorting

Sorry , which other purpose do you know a sorting algorithm would solve ?


DarkHamster
DarkHamster
actually for several thousand elements, I would use radix -- its the only sorting algorithim that works in linear time, and it is the most efficient for large amounts of work.


"There is no dark side of the moon really,
As a matter of fact, its all dark."
LilBudyWizer
LilBudyWizer
A mergesort involves a merge of multiple files which is a relatively simple matter yet many programmers still attempt a naive approach using nested if statements resulting in 2^n cases which is not practical for large numbers of files. You are quite right that a sort algorithm sorts, but I do not argree that the only practical reason to learn a specific algorithm is to use it in its entirity. My limited experience programming is that you beg, borrow and steal every little technique you can find and combine them in new and fascinating ways, at least to yourself, to complete the task at hand.
Keys to success: Ability, ambition and opportunity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.