aspose file tools*
The moose likes Beginning Java and the fly likes number sorting algorithms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "number sorting algorithms " Watch "number sorting algorithms " New topic
Author

number sorting algorithms

Michael Keisu
Ranch Hand

Joined: Oct 08, 2009
Posts: 30
I read Bubblesort was bad, unfortunately by then I had already learned it , So I learned the Selection Sort, which is from what I gather better but still not very efficent for large arrays.

I am wondering how the different sorting algorithms rank by performance? and which are the least complex ones to learn? I'm particularly interested in the beginner-intermediate ones, because the more complex ones I don't think I could grasp.

Ah, I am well aware of the Arrrays.sort() from the java API, but that just isn't as much fun

Thanks,
Mike
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

If somebody told you bubble sort was bad, they were wrong - because that is not the COMPLETE story. Different sorts all have strengths and weaknesses. Bubble sorts are great if the data is already mostly sorted. For example, take something like a phone book. It's already sorted. If you want to add 10 names, you can stick them at the end, and use a bubble sort. It would run pretty quick.

Something like a Quicksort, which is good for randomly distributed data, would be HORRIBLE on an already sorted list.

Bubble sort is one of the least complex, which is usually why you learn it first. You can find entire college classes on this topic. Donald Knuth wrote a famous series of books on computer programming. One of them (an entire book) is on nothing but searching and sorting.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
#24 in the http://faq.javaranch.com/java/JavaBeginnersFaq should be of interest to you.


Ping & DNS - my free Android networking tools app
Michael Keisu
Ranch Hand

Joined: Oct 08, 2009
Posts: 30
Thanks guys - appreciate the quick replies.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: number sorting algorithms