I have a recursion limit error in my quick sort program although I set recursion limit to 1500
up vote
-1
down vote
favorite
I am trying to write an in-place program that would use the quicksort algorithm to sort a list. But it keeps giving an error:
maximum recursion depth exceeded while calling python object.
Although I tried setting recursion limit.
def partition(L,low,high,comparison):
i=low-1
pivot=random_pivot(L)
for j in range(low,high):
if comparison(L[j],pivot):
i+=1
L[i],L[j]=L[j],L[i]
L[i+1],L[high]=L[high],L[i+1]
return i+1
def inplace_Quicksort(L,low,high,comparison):
low=0
high=len(L)-1
if comparison(low,high):
pivot_index=partition(L,low,high,comparison)
inplace_Quicksort(L,low,pivot_index-1,comparison)
inplace_Quicksort(L,pivot_index+1,high,comparison)
print(L)
Can you please have a look at it and explain to me what is wrong? Thank you so much.
python sorting quicksort
New contributor
add a comment |
up vote
-1
down vote
favorite
I am trying to write an in-place program that would use the quicksort algorithm to sort a list. But it keeps giving an error:
maximum recursion depth exceeded while calling python object.
Although I tried setting recursion limit.
def partition(L,low,high,comparison):
i=low-1
pivot=random_pivot(L)
for j in range(low,high):
if comparison(L[j],pivot):
i+=1
L[i],L[j]=L[j],L[i]
L[i+1],L[high]=L[high],L[i+1]
return i+1
def inplace_Quicksort(L,low,high,comparison):
low=0
high=len(L)-1
if comparison(low,high):
pivot_index=partition(L,low,high,comparison)
inplace_Quicksort(L,low,pivot_index-1,comparison)
inplace_Quicksort(L,pivot_index+1,high,comparison)
print(L)
Can you please have a look at it and explain to me what is wrong? Thank you so much.
python sorting quicksort
New contributor
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
2
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
What israndom_pivot
, and why do the arguments involve no range information?
– user2357112
Nov 10 at 16:17
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am trying to write an in-place program that would use the quicksort algorithm to sort a list. But it keeps giving an error:
maximum recursion depth exceeded while calling python object.
Although I tried setting recursion limit.
def partition(L,low,high,comparison):
i=low-1
pivot=random_pivot(L)
for j in range(low,high):
if comparison(L[j],pivot):
i+=1
L[i],L[j]=L[j],L[i]
L[i+1],L[high]=L[high],L[i+1]
return i+1
def inplace_Quicksort(L,low,high,comparison):
low=0
high=len(L)-1
if comparison(low,high):
pivot_index=partition(L,low,high,comparison)
inplace_Quicksort(L,low,pivot_index-1,comparison)
inplace_Quicksort(L,pivot_index+1,high,comparison)
print(L)
Can you please have a look at it and explain to me what is wrong? Thank you so much.
python sorting quicksort
New contributor
I am trying to write an in-place program that would use the quicksort algorithm to sort a list. But it keeps giving an error:
maximum recursion depth exceeded while calling python object.
Although I tried setting recursion limit.
def partition(L,low,high,comparison):
i=low-1
pivot=random_pivot(L)
for j in range(low,high):
if comparison(L[j],pivot):
i+=1
L[i],L[j]=L[j],L[i]
L[i+1],L[high]=L[high],L[i+1]
return i+1
def inplace_Quicksort(L,low,high,comparison):
low=0
high=len(L)-1
if comparison(low,high):
pivot_index=partition(L,low,high,comparison)
inplace_Quicksort(L,low,pivot_index-1,comparison)
inplace_Quicksort(L,pivot_index+1,high,comparison)
print(L)
Can you please have a look at it and explain to me what is wrong? Thank you so much.
python sorting quicksort
python sorting quicksort
New contributor
New contributor
edited Nov 10 at 19:44
Strawberryshrub
705214
705214
New contributor
asked Nov 10 at 16:11
Asmaa Hadir
11
11
New contributor
New contributor
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
2
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
What israndom_pivot
, and why do the arguments involve no range information?
– user2357112
Nov 10 at 16:17
add a comment |
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
2
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
What israndom_pivot
, and why do the arguments involve no range information?
– user2357112
Nov 10 at 16:17
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
2
2
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
What is
random_pivot
, and why do the arguments involve no range information?– user2357112
Nov 10 at 16:17
What is
random_pivot
, and why do the arguments involve no range information?– user2357112
Nov 10 at 16:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
You are resetting the range to the complete list each time you call inplace_Quicksort
in the first two lines of its code, thereby making the arguments low
and high
useless.
This leads to an endless recursion. No increase of maximum recursion depth will help you.
Instead give your arguments a default value. Look how it is done in this answer.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You are resetting the range to the complete list each time you call inplace_Quicksort
in the first two lines of its code, thereby making the arguments low
and high
useless.
This leads to an endless recursion. No increase of maximum recursion depth will help you.
Instead give your arguments a default value. Look how it is done in this answer.
add a comment |
up vote
1
down vote
You are resetting the range to the complete list each time you call inplace_Quicksort
in the first two lines of its code, thereby making the arguments low
and high
useless.
This leads to an endless recursion. No increase of maximum recursion depth will help you.
Instead give your arguments a default value. Look how it is done in this answer.
add a comment |
up vote
1
down vote
up vote
1
down vote
You are resetting the range to the complete list each time you call inplace_Quicksort
in the first two lines of its code, thereby making the arguments low
and high
useless.
This leads to an endless recursion. No increase of maximum recursion depth will help you.
Instead give your arguments a default value. Look how it is done in this answer.
You are resetting the range to the complete list each time you call inplace_Quicksort
in the first two lines of its code, thereby making the arguments low
and high
useless.
This leads to an endless recursion. No increase of maximum recursion depth will help you.
Instead give your arguments a default value. Look how it is done in this answer.
answered Nov 10 at 16:18
trincot
112k1476108
112k1476108
add a comment |
add a comment |
Asmaa Hadir is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa Hadir is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa Hadir is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa Hadir is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240830%2fi-have-a-recursion-limit-error-in-my-quick-sort-program-although-i-set-recursion%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try to debug your code yourself to see why the code recurses infinitely many times.
– user202729
Nov 10 at 16:16
2
Please be so good to not destroy the constructive edits made by others.
– trincot
Nov 10 at 16:16
What is
random_pivot
, and why do the arguments involve no range information?– user2357112
Nov 10 at 16:17