Iteration or Recursion for Quick Sort?
Of course, the main question now is: which solution to go for, iterative
or recursive
?
I would still advise you to go for the iterative
solution. Imagine sorting an array with a million items. The system stack would need to save a significant number of records of the quick sort
function. It opens you up to problems, like running out of memory, resulting in segmentation faults, etc.
Having said that, the recursive
version is so much easier to write and understand. So I would go for implementing a recursive version first (and for interviews), and then thinking about how to implement it iteratively using your own stack (optimize later).