Question: Consider a recursive function called permuteR ( string , position ) that returns each reordering of the letters in a string. def swap ( s

Consider a recursive function called permuteR (string, position) that returns each reordering of the letters in a string.
def swap(st,1,r) :
st = list(st)
st 1,st [r]=st[r], st[1]
return ''.join(st)
def permuteR(st,l=0 :
if len(st)==1 :
return [st]
L=[]
for i in range(1, len(st)):
st =swap(st,i,l)
L += permuteR(st, l+1)
st =swap(st,i,1)
return L
print(permuteR("123"))
# ['123','132','213','231','321','312']
What is the recurrence relation of pe rmuteR?
T(n)=K+(n-1)**T(n-1)
T(n)=K+T(n-1)
T(n)=K+T(nlog(n))
T(n)=K+T((n+1)log(n))
 Consider a recursive function called permuteR (string, position) that returns each

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!