Iterative quicksort or quicksort? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Iterative quicksort or quicksort?

In which cases iterative one is faster? What are iterative version's advantages

27th May 2020, 10:58 PM
Yasemin - avatar
2 Answers
+ 3
There is an iterative and a recursive version of quicksort. They both have a time complexity of O(n log n) with worst case of O(n²). However, the iterative version is faster, but has a greater space complexity due to its use of a data structure to simulate the recursion call stack. Here's an example of a recursive quicksort.
27th May 2020, 11:11 PM
ChaoticDawg - avatar
+ 1
Thank you
27th May 2020, 11:16 PM
Yasemin - avatar