Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python implementation of quicksort without recursion?

I am attempting to implement quick sort in Python without using recursion, but all reference implementations or pseudo codes I have found so far use recursion.

The reason for this is that I will adapt this non-recursive implementation to run on GPUs using Numba, and I cannot make recursive calls there.

Is there a quick sort implementation for a 1d array (say, a Numpy array or Python list) that does not use recursion?

Thanks,

Eduardo

like image 515
Edy Bourne Avatar asked Aug 29 '26 07:08

Edy Bourne


1 Answers

The standard unix/linux qsort is implemented without recursion for efficiency. You could look that up, or just translate the code in this answer to python:

Can quicksort be implemented in C without stack and recursion?

like image 138
Igor Rivin Avatar answered Aug 30 '26 19:08

Igor Rivin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!