473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

List<T> sort performance

Hi,

Can I expect a clever sorting algorithm behind the Sort() function for the
List<Tclass? Can't find anything on the net that says anything about this.

regards Jesper
Sep 30 '07 #1
3 2793
Jesper wrote:
Hi,

Can I expect a clever sorting algorithm behind the Sort() function for the
List<Tclass? Can't find anything on the net that says anything about this.

regards Jesper
Yes. The List<>.Sort method uses Array.Sort, which uses the quick sort
algorithm.

--
Göran Andersson
_____
http://www.guffa.com
Sep 30 '07 #2
"Jesper, Denmark" <Je***********@discussions.microsoft.comwrote in message
news:96**********************************@microsof t.com...
Hi,

Can I expect a clever sorting algorithm behind the Sort() function for the
List<Tclass? Can't find anything on the net that says anything about
this.

While I wouldn't call quicksort particularly "clever" :), I believe that is
the algorithm used to sort List<T>. That being said, quicksort is not so
good (O(n^2)) if the list is sorted or almost sorted unless the pivot point
is randomized (which brings it back to high probability of O(nlgn)), and I
don't know that the Framework's implementation does that. So, if your lists
fall into this "almost sorted" category (and you are either sorting large
lists or sorting lists very often), I would ensure that you profile at some
point to make sure you're not spending an inordinate amount of time sorting.
If that's the case, you're going to want to either keep the list sorted from
the get go or use a different sort implementation.

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 30 '07 #3
M
On Sep 30, 2:09 pm, Jesper, Denmark
<JesperDenm...@discussions.microsoft.comwrote:
Hi,

Can I expect a clever sorting algorithm behind the Sort() function for the
List<Tclass? Can't find anything on the net that says anything about this.

regards Jesper
Hi Jesper,

I think you have you'r answere already, but I still want to recommend
you Reflector, in case you don't know it yet.
With that tool you can view the source of any .Net assembly, including
the .Net framework. Sow it can give you
answeres on questions like these.

You can find it at http://www.aisto.com/roeder/dotnet/

Kind regards,

Mario

Oct 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
4
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>....
4
by: =?Utf-8?B?TGFycnlS?= | last post by:
I need some help with a multilevel sorting problem with the List<>. I have a List<ItemToSort( see below ) that needs to be sorted in the following manner: Sort by Level1Id ( ok that was the easy...
0
by: Iron Moped | last post by:
I'm airing frustration here, but why does LinkedList<not support the same sort and search methods as List<>? I want a container that does not support random access, allows forward and reverse...
44
by: Zytan | last post by:
The docs for List say "The List class is the generic equivalent of the ArrayList class." Since List<is strongly typed, and ArrayList has no type (is that called weakly typed?), I would assume...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
0
by: Marc Gravell | last post by:
I would like to know how to write this in LINQ You don't need LINQ for this; you can sort the existing list using a Comparer<T>: List<InterfaceBaselist = new List<InterfaceBase>(); ...
9
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've an optimization question for you all really quick. I have a stream that I am reading some bytes. At times, the stream can contain a small amount of bytes such as 50...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.