just as the title says, there is more loops for this week, how fun! ..... I have done some reading since, and I figured that just proving a recursive function is not so hard, by using induction, well..., at least for some recursive functions.
So basically for a recursive function, there will be some "base case", which will terminate the program, and return or not, depending on the program, the value to the user. This part can just easily go to the induction step "base case". Hey, thier same names might have suggested something already! Then for the induction step, you assume either P(n) or <P(0)...P(n-1)>, depending on the recursive function. Then you see that n+1 or n does not fall into the base case part, so you can go the "if statements". Each if statement corresponds to one case, and inside the loop, it will do something before doing a recursive call, usually the position of start, or end, and in either form of a statement or changing the parameters.
Then you just argue that if the statement or the change of parameteres make any sense, if so, since the recursive call has a smaller size now, the recursive call must be correct by the assumption, then we can conclude that if the recursive call is right.
It didn't occur to me that a recursive function is just like a induction until I do some past tests, which I reluctantly review at first, but later become happy since I found out that the test has somewhat the same question come out of it. This new way of thinking kind of excites me, and yes i am a nerd, shut up! but I really think that it will come in handy some day.
No comments:
Post a Comment