2014年3月2日星期日

Week 7(Recursion)

Recursion is a problem solving technique in which a function calls itself. A  recursive function has two parts. First: the base case. The base case is the smallest part to solve. It usually returns some value. The second part of a recursive function is where the problem is broken down into one or more smaller parts and that's why it is called recursion. It will use itself inside the smaller part. This helps us solving many problem. However a problem with recursion is memory usage. Each time the function calls itself we have to keep the previous variables it was using in memory. When function reaches the base case the stack can be huge and slowing down the program. For example, the A1.

没有评论:

发表评论