7 ms·
I get your point, but why would you pick bubble sort? That’s one any engineer should be able to implement without any help. It’s the more complex/useful ones w
by dickeytk 7y ago
I get your point, but why would you pick bubble sort?
That’s one any engineer should be able to implement without any help. It’s the more complex/useful ones worth discussing.
Even Obama knows this: https://m.youtube.com/watch?v=k4RRi_ntQc8 https://m.youtube.com/watch?v=k4RRi_ntQc8
- starbugs 7y agoI picked bubble sort, because it's literally the example from the first sentence of the article: > David Hansson, the creator of Ruby on Rails, admitted in a tweet that he wouldn’t be able to write bubble sort on a whiteboard.
- dragontamer 7y agoI wouldn't be able to write a bubble-sort specifically. But if I were asked to "sort" a set of numbers, I'm sure I'd come up with some unholy combination of bubble, selection, and insertion sort that got the job done. I always have to consult the books to remember the difference between bubble, insertion, and selection sorts. But even without documentation, surely people can write a list of numbers (ex: 9, 4, 5, 3, 2, 6, 0, 1, 8, 7), and then tinker with an algorithm until that list was in order? (0 1 2 3 4 5 6 7 8 9) ------------ Here's the thing about programming: you don't have to travel very far before you get into the "nobody knows the answer". The internet provides enough information for the first ~2 months on the job. Specialized books on your topic (ex: GPUs, HPC, OpenMP, etc. etc.) may cover another 1 or 2 months of training on the job. After that? Nobody in the world is doing what you do. Nobody has to work with your particular configuration of tools, your particular problems (performance? Bugs? Architecture?). Your particular office politics. Literally no one else in the world. And yet, you'll be responsible for coming up with a solution that works, even without any guides. That's why people like testing people "without the internet". Because in most cases, there's no guide to tell you how to progress a real project in the real world.
- a_t48 7y agoMergesort is also worth looking into.
- mark-r 7y agoMerge sort is wonderful. Not only is it as easy to remember as bubble sort, but is there anything else that can work with data that doesn't all fit in memory?
- dragontamer 7y agoStrangely enough, I always found quicksort easier to write than Mergesort. But that's probably just how my mind works. Hmmm... with Mergesort, you gotta be copying the data to new buffers, malloc-ing arrays and new arrays, managing the data etc. etc. Quicksort can be trivially done in-place. And yes, I know Merge-sort has an in-place variation, but in-place Mergesort is non-intuitive IMO. ------- I guess merge-sort is easy if you are willing to call malloc / free (or new / delete) over-and-over again. But those functions scare me. I prefer to get things done without dynamic memory, especially if its a whiteboard interview. Quicksort does require more brainpower than selection / insertion / bubble sorts. But if I were to use a recursive methodology, trying to do quicksort would be my strategy.
- a_t48 7y agoMergesort sticks in my memory better, for whatever reason. And yes, definitely agree that in real life, avoid those allocations. For a whiteboard interview, declare an std::vector and call it a day, no need to manually call new and delete.
- dickeytk 7y agoOh my, I’m that guy today. Whoever said it, I have a super hard time believing DHH couldn’t implement bubble sort on a whiteboard. Am I the only one? I get that people hate whiteboard/algorithm interviews, but bubble sort? for i = 0..n: for j = i..n: if arr[i] > arr[j]: arr[j], arr[i] = arr[i], arr[j] Everyone in this field should be able to do this, maybe not right away, maybe not without bugs, but with help within 45 minutes.
- LandR 7y agoYeah, this is barely a step above fizzbuzz. If you can't do that without help in 45 minutes, what can you actually do? I think the actual problem is most developers / programmers are just bad at the job, and then go in a huff when this is pointed out.
- jcranmer 7y agoOff the top of my head, I could write selection sort, insertion sort, merge sort, quick sort, and with a few minutes of thinking about it, even heapsort. But bubble sort? It's a useless sort, even worse than selection and insertion sort, which have their advantages in certain circumstances. So I don't bother to remember what the algorithm for bubble sort is in the first place.
- seba_dos1 7y agoDo you learn algorithms by blindly memorizing their steps? There's nothing to remember in bubble sort, if you know that it "bubbles" by swaping the elements you're already done.
- dragontamer 7y agoThe main "issue" I have is that if you write a "bubble" sort backwards, then its suddenly insertion sort instead and much more efficient. For people who know about knots out there... its like asking for somebody to tie a Granny Knot instead of a square-knot. Anyone who actually practiced knot-tying will "accidentally" tie a square-knot instead (because the square-knot is stronger for the same level of effort). Similarly, bubble sort is the "bad" way to write insertion sort. Anybody who actually practiced writing sorts will write insertion sort by accident instead.
- seba_dos1 7y agoIt's either an exaggeration, or his mind works in some very special ways. You don't need to memorize multiplication table to be good at math, but this is an equivalent of saying "I wouldn't even be able to add two numbers together in my head!".
- clarry 7y ago> That’s one any engineer should be able to implement without any help. If I wrote it down every time someone claims that "this is so important any engineer should know it," I'd have a book as thick as the bible full of trivia. All of it so easy, and yet in every position you can find a person who hasn't mastered it all. Maybe it isn't all that important after all. Most of these people are capable of finding help should it come to that.
- dickeytk 7y agoI’m not saying that it’s important, I’m saying it’s trivial and an engineer should be able to figure it out. Bubble sort that is. Merge sort? Quick sort? Bogosort? Maybe not. But bubble sort yes. Just like an engineer even at the most junior level should be able to swap and write fizz buzz. If you can’t do that you certainly cannot call yourself an engineer.