| .NET DotNet Forum Index » VB.NET Forum (Visual Basic .NET) » Fastest sorting algorithm... |
|
Page 1 of 1 |
|
| Author |
Message |
| Andrius B.... |
Posted: Thu Nov 05, 2009 1:53 pm |
|
|
|
Guest
|
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. |
|
|
| Back to top |
|
|
|
| Nobody... |
Posted: Thu Nov 05, 2009 3:24 pm |
|
|
|
Guest
|
"Andrius B." <andriusbl at (no spam) mail.lt> wrote in message
news:uZO$vkkXKHA.3612 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote: 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 |
|
|
| Back to top |
|
|
|
| Miro... |
Posted: Thu Nov 05, 2009 4:39 pm |
|
|
|
Guest
|
I am not sure if your own aglorithm is faster or slower,
or how much work it would take for you to convert your list...
but a hashtable auto sorts for you ...and it accepts 2 values just like you
said.
http://www.c-sharpcorner.com/UploadFile/prasoonk/HowToSortHashtable05202008034844AM/HowToSortHashtable.aspx
"Andrius B." <andriusbl at (no spam) mail.lt> wrote in message
news:uZO$vkkXKHA.3612 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote: 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.
|
|
|
| Back to top |
|
|
|
| James Hahn... |
Posted: Thu Nov 05, 2009 5:37 pm |
|
|
|
Guest
|
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 B." <andriusbl at (no spam) mail.lt> wrote in message
news:uZO$vkkXKHA.3612 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote: 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.
|
|
|
| Back to top |
|
|
|
| Family Tree Mike... |
Posted: Thu Nov 05, 2009 6:14 pm |
|
|
|
Guest
|
Andrius B. wrote:
Quote: 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?
--
Mike |
|
|
| Back to top |
|
|
|
| Herfried K. Wagner [MVP]... |
Posted: Sat Nov 07, 2009 6:40 pm |
|
|
|
Guest
|
Family Tree Mike schrieb:
Quote: 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.
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.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/> |
|
|
| Back to top |
|
|
|
|