Cannot understand the detailedly the following code

A.T.Hofkamp hat at se-162.se.wtb.tue.nl
Tue Apr 8 08:45:35 EDT 2008


On 2008-04-08, reachmsn at hotmail.com <reachmsn at hotmail.com> 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



More information about the Python-list mailing list