Fastest sorting algorithm

  • Thread starter Thread starter Andrius B.
  • Start date Start date
A

Andrius B.

Hi all.

The question for advanced programers:
I have a list of objects (custom types), the count of the list varies from
1000 to 100 000.
What algorithm could be the fastest for sorting such a list?
My data type has only two members (ID as integer and name as string). ID's
are unique, so the sorting would be by IDs only (if comparing).

I use VB 2005.

Thanks in advance.
 
Andrius B. said:
Hi all.

The question for advanced programers:
I have a list of objects (custom types), the count of the list varies from
1000 to 100 000.
What algorithm could be the fastest for sorting such a list?
My data type has only two members (ID as integer and name as string). ID's
are unique, so the sorting would be by IDs only (if comparing).

I use VB 2005.

See a list of sorting algorithms here:

http://en.wikipedia.org/wiki/Sorting_algorithm
 
It depends on the data. Some algorithms are poor when the data is
completely random, but come out on top when only a few items are out of
sequence. It also depends on whether or not you need the sort to be
stable - that can make a big difference to the sort speed.

It also depends on what you are comparing and how complex the compares are.
Some algorithms keep the number of comparisns as low as possible, and are
thus faster when the comparison is complex (eg, text comparisons that are
culture-sensitive) Other algorithms rely on more comparisons but use a
faster sort process, so will be better when the comparison is simple, such
as integers.
 
Andrius said:
Hi all.

The question for advanced programers:
I have a list of objects (custom types), the count of the list varies from
1000 to 100 000.
What algorithm could be the fastest for sorting such a list?
My data type has only two members (ID as integer and name as string). ID's
are unique, so the sorting would be by IDs only (if comparing).

I use VB 2005.

Thanks in advance.

Is List.Sort(AddressOf somecomparefunction) too slow?
 
Family said:
Is List.Sort(AddressOf somecomparefunction) too slow?

'List(Of T).Sort' uses quicksort internally, which is pretty fast for
arbitrary data (runtime complexity Theta(n log n)).

Vastly improved performance can only be achieved if the items you are
attempting to sort have certain known characteristics.
 
Back
Top