programing is a pleasure!
First,Let's know the principle:Recursive leap of faith-When you try to understand a recursive program,you must be able to put the underlying details aside and focus instead on a single level of the operation. At that level,you are allowed to assume that any recursive call automatically gets the right answer as long as the arguments to that call are simpler than the original arguments in some respect.The psychological strategy-assuming that any simpler recursive call will work correctly-is called the recursive leap of faith!The idea may be difficult to newers! Take an example for it:We all know the Fibonacci function:F(n)=F(n-1)+F(n-2)Recursive implementation of the Fibonacci funtion:
if n is 5,Fib(5) is computed by the sum of Fib(4) and Fib(3).Applying the faith,you can assume that the program correctly computes each of these values,without going through all the steps that Fib(4) and Fib(3) is computed!
posted on 2008-03-16 18:54 丑石 阅读(276) 评论(0) 编辑 收藏 引用 所属分类: Algorithm and Data Structure
Powered by: C++博客 Copyright © 丑石