0
M=[[0, 0, 0, 0, 0, 0, 0],[1, 0, 0, 1, 0, 0, 1],[2, 1, 0, 0, 1, 0, 0]]

def t(M,maxi,maxj,compare):
    ma=0
    maxi = maxj = 0
    for i in range(0,3):
        for j in range(0,7):
            if M[i][j] < 2 and ma <= M[i][j]:
                ma = M[i][j]
                maxi = i
                maxj = j
    return(ma, maxi, maxj)

How can I write a recursive function such that it computes the M[i,j] based on comparing conditions and does it till it reaches M[0,j] (any j). I have tried to write a recursive function as of now :

def recursive_tracking(M,maxi,maxj):
    for i in range(1,maxi):
        for j in range(1,maxj):
             M[i,j]=max(M[i-1,j],M[i,j-1],M[i-1,j-1])
             return recursive tracking(M,i,j)
    return i,j
Mike Müller
  • 82,630
  • 20
  • 166
  • 161
  • 1
    Hint: you can emulate the assignments that take place before the loop with default parameters. – TigerhawkT3 Dec 04 '15 at 05:39
  • I didn't understand... –  Dec 04 '15 at 06:01
  • hi @TigerhawkT3 Can you please elaborate..it will be helpful.. –  Dec 04 '15 at 06:37
  • 2
    Read the "default parameters version" of [this question's top answer](http://stackoverflow.com/questions/30214531/basics-of-recursion-in-python). – TigerhawkT3 Dec 04 '15 at 06:57
  • @TigerhawkT3 I updated the recursion code.Can you suggest me if i m right with return command ? –  Dec 04 '15 at 07:05
  • Right now, your code has some loops but no stop condition. Recursion generally means the opposite of that. I recommend looking through some more information on recursion instead of asking us to bugfix an iterative function into a recursive one. – TigerhawkT3 Dec 04 '15 at 07:14

0 Answers0