wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes duplicate values in sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "duplicate values in sort" Watch "duplicate values in sort" New topic
Author

duplicate values in sort

Senaca Boyd
Greenhorn

Joined: Feb 21, 2007
Posts: 9
If I have an array that is not sorted and contains duplicate values, which of these sorting techniques will successfully accomplish my sort: heap sort, selection sort, or bubble sort?
[ April 05, 2007: Message edited by: Senaca Boyd ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11419
    
  16

what do you mean by "successfully accomplish my sort"? all of these techniques will sort the array.

could you be more specific in your question?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Senaca Boyd
Greenhorn

Joined: Feb 21, 2007
Posts: 9
I thought there were some sort techniques that would not work if one of the values being sorted was a duplicate. Am I wrong?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11419
    
  16

i don't remember which of these are which, but there is the concept of a 'stable' vs. 'unstable' sort.

this concept relates to how you handle two items with the same key. in a stable sort, the pre-sort order of items with the same key is preserved. an unstable sort makes no garantees either way.

this is more of an issue when you are sorting on multiple fields - say first and last name. if i sort by first name first, when i then sort by last name, i want to keep all the smiths in the order they came to me.

I don't know if that is what you were thining of or not. but if you are sorting on a single element, the sort algorithm shouldn't matter.

some may be more or less efficient, but again, i don't think that is what you were aiming towards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: duplicate values in sort