3 ms·
Mergesort is also worth looking into.
by a_t48 7y ago
Mergesort 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.