0

I have separate implementations of sorting algorithms on 2 separate files (one for divide and conquer and another for brute force algos). I was trying to benchmark them against each other so I in-cooperated all of them(via imports) into a single file which generates a random list of specified length and calls all sorting functions using said list as input and displays their running time, though my problem is specifically with quicksort (NOTE: This omits several other sorting functions called in the same form):

if __name__ == '__main__':
 size = int(sys.argv[1])
 input_list = randomgen(size)
 start = 0
 end = int(len(input_list)-1)

 print('Quick Sort:')
 start_time = time()
 quicksort(input_list, start, end)
 end_time = time()
 print('Run Time: ',(end_time-start_time))

When I call this function it throws a recursion depth error, specifically: 'RecursionError: maximum recursion depth exceeded in comparison' (though it works with input lists of sizes less than 100). When I try to do the same exact thing in the file containing only quick sort and merge sort with an input list of the same length it functions perfectly

So my question is: what could cause this behavior and is it advice-able to change the recursion depth of python if that's whats causing the error ?

EDIT: Turns out the error was caused by the pivoting scheme I was using(end instead of random). Thanks to @olisch for this link: Python Quicksort Maximum Recursion Depth

  • 1
    please have a look at: https://stackoverflow.com/questions/27116255/python-quicksort-maximum-recursion-depth That post include a great explanation regarding quicksort and python RecursionError. – olisch Oct 28 '18 at 12:02
  • Possible duplicate of [What is the maximum recursion depth in Python, and how to increase it?](https://stackoverflow.com/questions/3323001/what-is-the-maximum-recursion-depth-in-python-and-how-to-increase-it) – aydow Oct 28 '18 at 12:27
  • The link above yours suits my specific problem more. Thanks though. – Nelson Mongare Oct 28 '18 at 18:46

0 Answers0