2 ms·
Strangely 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 cop
by dragontamer 7y ago
Strangely 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.