我在Python中写了递归的QuickSort算法,以对10,000个INT列表进行排序。我正在测试一个最坏的情况(枢轴始终是较低的索引,并且列表已经对其进行排序,因此对QuickSort的递归调用始终为空,另一个始终降低1)。我知道这意味着我必须使用
sys.setRecursionLimit(10000)
现在增加错误代码
处理带有退出代码-1073741571(0xc00000fd)
,我应该使用
threeing.stack_size()
,但是,我不知道如何使用此功能。我尝试传递不同的值,并且要么要么明显大小无效,要么是相同的错误代码。有人可以帮我吗?
I wrote a recursive quicksort algorithm in Python to sort a list of 10,000 ints. I am testing a worst case (pivot is always the low index, and the list is already sorted, so one of the recursive calls to quicksort is always empty, and the other always decreases by 1). I know that means I have to increase the recursion limit with
sys.setrecursionlimit(10000)
Now I am getting the error code
Process finished with exit code -1073741571 (0xC00000FD)
I read elsewhere that I should use
threading.stack_size()
But, I have no idea how to use this function. I tried passing in different values, and I will either get that the size is not valid, or the same error code. Can somebody please help me with this?
发布评论
评论(1)
通过在较小的分区上递归并在较大的分区上循环,可以将堆栈空间限制为O(log(n))。最坏的情况时间复杂性仍然是O(n^2)。
Stack space can be limited to O(log(n)) by recursing on smaller partition, and looping on larger partition. Worst case time complexity is still O(n^2).