c++ - What is a good example of recursion other than generating a Fibonacci sequence? -


possible duplicates:
real-world examples of recursion
examples of recursive functions

i see programming language tutorial teach recursion using simple example how generate fibonacci sequence, question is, there example other generating fibonacci sequence explain how recursion works?

the classic binary tree search:

def findval (node,val):     if node == null:         return null     if node.val = val:         return node     if node.val > val:         return findval (node.left,val)     return findval (node.right,val)  findval (root,thing_to_find) 

that may little more complex simple formula it's "bread , butter" use of recursion, , illustrates best places use it, recursion levels minimised.

by mean: could add 2 non-negative numbers with:

def add (a,b):     if b == 0:         return     return add (a+1,b-1) 

but you'd find running out of stack space pretty large numbers (unless compiler optimised tail-end recursions of course, should ignore level of teaching you're concerned with).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -