On Apr 8, 5:45 pm, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote:
> On 2008-04-08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> [deleted a long piece of text by our BDFL about recursive graph path-finding 
> algorithm]
>
> > after first writing the inductive part ... for node in
> > graph[start] ....
> > and then by trial and error put square brackets around path in the
> > Basis part. Can someone please explain how to write this code. Thanks!
>
> The same as any other function.
> (the trick with recursive functions is not to think about recursion. Instead,
> pretend you are calling another function that happens to have the same name.)
>
> As for the actual procedure of writing a function:
>
> First define the input and output parameters/values of the function.
> (ie what goes in, and what comes out)
>
> For recursive functions, there are always two cases, a terminating case, and a
> reduction case. In the first case, you may not use the recursive function, in
> the latter function you should.
> Both cases should use the information available from the input parameters, and
> provide a result that matches with the output requirements of the function. 
> Add
> a if/then/else that distinguishes between what case you have, and you're done.
>
> Sincerely,
> Albert


Ok following these instructions one gets

def find_all_paths(graph, start, end, path=[]):
 path= path+ [start]

 for node in graph[start]:

   find_all_paths(graph, node, end, path)

Now >
> First define the input and output parameters/values of the function.
> (ie what goes in, and what comes out)

Now what will be the output parameters - there is a Return statement.
Input parameters are graph, vertexes start, node, end and path. Also
how would you write the terminating and reduction cases after this.
Actually i'm not clear how to proceed writing this recursive function.
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to