+ 1
backtracking
https://code.sololearn.com/cw7aGVNKm2dW/#py. The combination of for loop+recursion has made me confused. without a for loop, '0' is executed only one time according to the base case. However, when I call a function inside a for loop, 6 numbers 0 are executed.
9 Respuestas
+ 2
If you have a proper IDE, I suggest "Stepping" through the code, this might help explain the transformation
+ 1
I tried but I could not understand that part of the code. Im new to backtracking:((
+ 1
#does this kinda help?
#num is basically the step
def permute(i,length, num):
num+=1
print(num, 'i=',i)
print(num, 'length=', length)
if i==length:
print(0)
print(num,'i=',i)
print(num,'length=', length)
else:
for j in range(i,length):
print(num,'i=',i)
print(num,'length=', length)
permute(i+1,length, num)
string="abc"
string=list(string)
print(permute(0,len(string), 0))
'''it kinda helps illustrate where you're at in the loop/recursive operation. Dont get upset, recursive operations are difficult, but practice makes perfect.'''
+ 1
your code is more understandable thanks
0
I tried to watch yt videos but they did not help sr i am so dumb
0
Dont get angry with me:(( sr i am so stupid
0
backtracking is so complex
0
what are you trying to achieve? 😅
0
I'm trying to understand how a for loop works when it is combined with recursion. I am new to backtracking. i just understand recursion at basic level. Backtracking is sth too hard for me:)