This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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