Fastest sorting algorithm

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.
 
N

Nobody

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
 
J

James Hahn

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.
 
F

Family Tree Mike

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?
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top