File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

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

Joined: Mar 22, 2005
Posts: 42965
#24 in the should be of interest to you.
Michael Keisu
Ranch Hand

Joined: Oct 08, 2009
Posts: 30
Thanks guys - appreciate the quick replies.
I agree. Here's the link:
subject: number sorting algorithms
It's not a secret anymore!