Monday, July 27, 2009

What type of sort is c#'s built in sort for arrays?

int[] hello = {0, 5, 3};


hello.sort();





what kind of sort is that?


selection sort?


quicksort?





...could someone sort this out for me please :)

What type of sort is c#'s built in sort for arrays?
From "Array.Sort Method (Array)" at MSDN:





"This method uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.





On average, this method is an O(n log n) operation, where n is the Length of array; in the worst case it is an O(n ^ 2) operation."
Reply:I don't know for certain, but it's most likely an efficient quicksort. Why would it be something else?


No comments:

Post a Comment