![]() |
|
|
#1 |
|
Registered User
![]() |
Should Bubble Sort Be Taught?
Inspiration in this thread.
I think it tends to be the first sorting algorithm taught in many courses, but I struggle to understand why. It's not necessarily any simpler or easier to understand than insertion or selection sort. I really don't think it should be taught at all (except for maybe an aside as an example of a bad algorithm you should never ever use). I still see people in my course, 3 years in, using bubble sort for some small programming tasks because it was the first one taught to them, and thus they find it the easiest. Of course that's really their fault for not bothering to study complexity and performance of algorithms, but still, I think bubble sort should never have been taught as being in any way acceptable in the first place. Thoughts? |
|
|
|
|
Advertisement
|
|
To remove these adverts, please create an account, or log in! You must have an account to post anyway :-) |
|
|
#2 |
|
Registered User
![]() |
Unless the programming task is to explicitly implement a sorting algorithm, it would be best just to use whatever sort function is provided by the language you are using. This function should be highly optimised (for example read the paper here: http://citeseerx.ist.psu.edu/viewdoc...10.1.1.14.8162), and for general data sorting, you're unlikely to write anything better yourself.
So when sorting algorithms are being taught in college, I think what should be focused on is that multiple algorithms can solve a problem, but with different complexity, and different best/worst/average performances, and how to analyse algorithms to determine these. So when you are solving other problems you can use these techniques to avoid very inefficient approaches. Still, there's no good reason to even mention bubble sort when insertion-sort is always as good, but usually better and very easy to implement and understand. I guess it was the first algorithm that lecturers learnt so they continue with the tradition
|
|
|
|
|
|
#3 |
|
Registered User
![]() |
I don't see any particular harm in teaching it.
If people are using it 3 years into a programming course, the problem isn't that they were taught how to do bubble sort - there's something else that's going very wrong. Why are they still implementing their own sorting algorithms on an ad-hoc basis? Have they not learned to use libraries by now? Lets pretend they hate using other peoples libraries. You seem to imply they are reimplementing it each time. If they are using their own sorting algorithm again and again, why haven't they at least written their own version of quicksort by now, or something else they are reusing? Really, I don't think that problem has anything to do with them being taught bubblesort. I don't think its an algorithm particularly worth teaching - I think insertion sort is easier conceptually, but thats just me personally. But I don't see any harm, if it fits usefully into a first course on algorithms. Obviously programmers should be told when and when not to use it. But really, after 3 years, they should no longer need to be told this sort of thing - it should be obvious to them. If they aren't familiar with the absolute basics of complexity analysis, to the extent that they can reason themselves that its not a great algorithm to use on an ongoing basis, then they have bigger problems than that their data won't sort quickly.
__________________
10110101100101111001010011111100111111011100110011? |
|
|
|
|
|
#4 | |
|
Category Moderator
![]() Join Date: Apr 2003
Location: Dublin 1
Posts: 17,999
|
Quote:
As to why you'd teach bubble sort, well, you need some sort of baseline. And bubble sort does have one advantage - it might be slow and inefficient, but it is a good baseline for teaching purposes (as in, pointing out that it doesn't work well with caches and pipelines and then showing approaches which do; pointing out that it's slow and then showing faster approaches; and so on).
__________________
My Training log ● StochasticGeometry Boards.ie Wiki: Main Shooting Page ● List of clubs and ranges ● List of firearms dealers |
|
|
|
|
|
|
#5 |
|
Registered User
![]() |
Teach them all. The bubble sort is a "classic" - it makes sense in a real world environment, even if it isnt the most efficient algorithm. It helps to learn the basic search algorithms before trying to conquer some of the more obtuse academic (and alright - effficient) solutions.
__________________
Spiralli Business Solutions Web Design :: Content Management Systems :: Custom Web Applications :: Print Design Brand Merchandising :: Training :: Software Development |
|
|
|
|
|
#6 | |
|
Registered User
![]() |
Quote:
I agree its easier to get your head around than, say, quicksort, but dont see much advantage over insert sort.
__________________
10110101100101111001010011111100111111011100110011? |
|
|
|
|
|
|
#7 |
|
Registered User
![]() |
I suppose an advantage would be that understanding bubble sort is a stepping stone to understanding quicksort.
Re: why people wouldn't just use libraries on my course - I mean college assignments involving low level C stuff, not in a project for a software engineering course. |
|
|
|
|
|
#8 | |
|
Registered User
![]() |
Quote:
Even then, I'm at a loss as to why they'd right their own sorting algorithm each time, and not just reuse an implementation for earlier?
__________________
10110101100101111001010011111100111111011100110011? |
|
|
|
|
|
|
#9 |
|
Registered User
![]() |
No, it's not embedded hardware stuff and yes we do have access to C libraries. You're reading a bit too much into this, however. It's about the tendancy of students in my year to use bubble sort over insertion or selection sort when asked to implement a basic sorting algorithm (which, for example, we had to do for an assignment involving analysing the workings of a compiler this year).
Will they ever have to do this in a real life job? Probably not, but to think bubble sort is acceptable is a pretty poor programming mindset IMO. I suppose that perhaps the real question is why complexity analysis hasn't been taught well enough in my course... |
|
|
|
|
|
#10 | ||||
|
Registered User
![]() |
Quote:
If they are rewriting their own implementations every time rather than using the library, then its bad. Quote:
Quote:
For normal development, it doesn't matter whether they write bubble sort or insertion sort, either of those show 'a pretty poor programming mindset', if they do so in place of just using the provided library functions. Quote:
"bubble sort over insertion or selection sort" in your post. Are you aware of the relative complexities of these 3 algorithms? (also, vs, say quicksort etc)
__________________
10110101100101111001010011111100111111011100110011? Last edited by fergalr; 09-11-2009 at 17:36. |
||||
|
|
|
|
|
#11 | |
|
Registered User
![]() |
Quote:
Forget about what I said about my year. We have some courses where we're expected to use libraries, we have others where we're not really encouraged to. The relative merits and demerits of this is a discussion for another thread. Last edited by Herbal Deity; 09-11-2009 at 17:56. |
|
|
|
|
|
|
#12 | |
|
Registered User
![]() |
Quote:
In a situation where people just have a few things to sort in a toy program, and aren't allowed use a library or reuse code from elsewhere (in 3rd year??), then I don't see much difference as to whether they use bubble or insertion sort. Personally, I don't have an issue if people want to teach it as the first example of a sorting algorithm. I'd prefer to teach selection sort as being more basic, insertion sort as being an improvement on that, and then bubble sort as an interesting variation that doesn't improve much. But thats just personal preference, because I notice that bubble sort takes some people a while to 'get', whereas noone has a problem with selection sort :-) I'd probably also teach people to generate all permutations, and check which one was sorted.
__________________
10110101100101111001010011111100111111011100110011? |
|
|
|
|
|
|
#13 |
|
Registered User
![]() |
I reckon it should, if only because it's one of the easiest for a student to generalise into an algorithm with an independant comparator. ("I want you to sort these objects. Don't know how to order 2 of those objects? Here, I'll give you a function that decides for you.")
I work with scripting languages a lot (perl and some python mostly), and one of the things I occasionally have to do is sort something arbitrary. That means developing a function that will compare 2 of those arbitrary objects and give a result that will order the two. If I happen to confuse myself while working on it, I think about it in the context of a bubble sort. Sure, a comparator is the core to any of those sorting algorithms but bubble is a nice way to think about it. Also, correct me if I'm wrong, but I remember hearing that bubble isn't so bad when you think of it in multi-processor situations; sure it's still O(n^2), but it can be easily adapted so it scales relatively evenly across the processors, as opposed to some that can't divide the work out into independant units of work. (That said, I still really like merge sorts - can be made to scale well across processors, and is a beautiful algorithm) (Also to be noted, I don't do multi-threaded programming myself, so I'm not speaking from experience) As others have said, most of the time, the students should be using libraries anyway, so the algorithm itself doesn't matter, but if they need to think about it in a concrete way, the bubble sort isn't that headwrecking. Just my 2c, Aoife
__________________
"Magick" - The Pagan Equivalent of £337 |
|
|
|
|
|
#14 | |
|
Moderator
![]() |
Quote:
Learn and understand an algorithm. Then learn another which is never worse in performance. Then find some which can be better, depending on certain factors. Learn how to abstract those lessons and you've learned far more valuable stuff then how to sort.
__________________
Science begets knowledge; opinion, ignorance. Hippocrates |
|
|
|
|
|
|
#15 | |||
|
Registered User
![]() |
Quote:
Quote:
Quote:
![]()
__________________
10110101100101111001010011111100111111011100110011? |
|||
|
|
|
![]() |
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|