For example, when writing some algorithms on graphs like
def f(graph):
#graph is dictionary of pairs vertex_i:{set of edges (i,j)} for 1<=i,j<=n
def g(vertex):
for vertex1 in graph:
do sth
...
for (i,j) in graph[vertex1]:
...
g(j)#recursive call
...
return ...
return g(1)
limited depth of recursion is sometimes very annoying, because code becomes much longer and more complicated if you have to avoid recursion. Is there a way to reach unlimited depth? Maybe you can describe your general solution of the problem on the following method
def nthNumber(n):
if n==1: return 1
else: return nthNumber(n-1)+1
(I know it's simple stupid and please don't give answers like "You should have written just nthNumber(n): return n " - I'm intrested in general solution). Thanks for help!