List.Sort() Stability? Reliability...?
-
I remember reading an article that said that List.Sort() was not necessarily reliable, but I cannot remember the context.. Does anyone know the reference or know of a sample (extra credit) that I can look at? I believe it was someones example of a "better" sorting algorithm... Thanks in advance.
I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
-
I remember reading an article that said that List.Sort() was not necessarily reliable, but I cannot remember the context.. Does anyone know the reference or know of a sample (extra credit) that I can look at? I believe it was someones example of a "better" sorting algorithm... Thanks in advance.
I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
MSDN says List.Sort uses Array.Sort which is a QuickSort implementation. unreliable? if it does not sort correctly or in a finite time, it is not an algorithm and not worthy to be part of .NET unstable? correct (confirmed by http://en.wikipedia.org/wiki/Quicksort[^]). I hope you know what it means. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
MSDN says List.Sort uses Array.Sort which is a QuickSort implementation. unreliable? if it does not sort correctly or in a finite time, it is not an algorithm and not worthy to be part of .NET unstable? correct (confirmed by http://en.wikipedia.org/wiki/Quicksort[^]). I hope you know what it means. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Learn something new every day. BTW, 10^6 seconds is a finite amount. O(n)=n^2 can be scary on large sets.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me
-
Learn something new every day. BTW, 10^6 seconds is a finite amount. O(n)=n^2 can be scary on large sets.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me
Ennis Ray Lynch, Jr. wrote:
Learn something new every day.
Same here. I've used the List.Sort() method for years but I've never had any trouble with it. Maybe because I only use List<> for small collections only.
The mind is like a parachute. It doesn’t work unless it’s open.
-
MSDN says List.Sort uses Array.Sort which is a QuickSort implementation. unreliable? if it does not sort correctly or in a finite time, it is not an algorithm and not worthy to be part of .NET unstable? correct (confirmed by http://en.wikipedia.org/wiki/Quicksort[^]). I hope you know what it means. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Do you have an alternative that you use?
The mind is like a parachute. It doesn’t work unless it’s open.
-
Do you have an alternative that you use?
The mind is like a parachute. It doesn’t work unless it’s open.
Most of the time I don't collect millions of objects, and I use the built-in Sort method. When it is really important, I apply special data structures and keep the "collection" sorted while building it up. Think of a list of lists, so items can be added to the right sub-list straight away. I trust others will suggest you keep huge amounts of data in a database and rely on its sorting capabilities. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I remember reading an article that said that List.Sort() was not necessarily reliable, but I cannot remember the context.. Does anyone know the reference or know of a sample (extra credit) that I can look at? I believe it was someones example of a "better" sorting algorithm... Thanks in advance.
I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
As you've been told, the sort method isn't really suitable on large data sets. It's important to understand that this is really the wrong place to apply sorting on large data sets - assuming it's coming from a database then the best way to do this is to retrieve the data already sorted and then fill the list.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.