This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting Algorithm in Collections  RSS feed

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks buddy mike for your valuable input
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!