Recursion (you have seen it before)






Problem Solving with Recursion

Recursion is a problem solving technique which uses recursion to solve problems

In general it looks like... def solve(p): if p is simple enough: s=simple solution to p else: break p into problems p1,...,pk where each of p1,...,pk 'looks like' p each of p1,...,pk is 'simpler' than p s1=solve(p1) # recursive call to solve s2=solve(p2) # recursive call to solve . . . sk=solve(pk) # recursive call to solve # combine the solutions to the smaller problems # into a solution s for p (our current problem) s=combine(s1,...,sk) return s