Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

number sorting algorithms

 
Michael Keisu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#24 in the http://faq.javaranch.com/java/JavaBeginnersFaq should be of interest to you.
 
Michael Keisu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys - appreciate the quick replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic