File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Sorting Algorithm in Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting Algorithm in Collections" Watch "Sorting Algorithm in Collections" New topic
Author

Sorting Algorithm in Collections

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi Folks,
java.util.Collections.sort(Comparable) uses merge sort to sort the elements. however quick sort is an in-place sorting algorithm, so it avoids the extra space/new array to keep sorted elements.so generally quick sort is bit faster than merge sort . but quick sort is not a stable . is this the only reason why merge sort[because it is a stable sort] is used in java.util.Collections.sort(Comparable)?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2982
    
    9
I believe it is, yes. Merge sort may be a little slower and use a little more memory, but when quicksort goes wrong, it's much worse. For a general-purpose sort, they (Sun engineers) appear to value general reliability most of all.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thanks buddy mike for your valuable input
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting Algorithm in Collections
 
Similar Threads
Difference between comparable and comparator
Merge Sorting. Same elements, what happens then?
Quicksort vs Merge Sort
Why Collections.sort is using merge sort insteadof quicksort?
Algorithms: Sorting data on basis of three columns