News for hackers. Stuff that matters.
Re:Programmers can’t write algorithms without help by dragontamer on Monday November 04, 2019 @12:06PM (#21443707)
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.

Re:Programmers can’t write algorithms without help by a_t48 on Monday November 04, 2019 @12:17PM (#21443821)
Mergesort 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.