What is Recursion?
If you are a student then you should know it! You studied it at the math class. Yes, and there’s no big difference between the math recursion method and the computer recursion method.
The recursion simply said: it’s to return and do the same work until arriving to a limit.
Let’s take the most popular sample; a factorial application with Tail recursion.
Function Factorial (Byval n as integer) As Double
If n < 0 then
Throw
New ArgumentException(“Invalid argument”)
Elseif n <= 1 Then
Return 1
Else
Return n * Factorial (n-1) ‘ The recursion is here
End If
End Function
The recursion is here! As I said it’s to return and do the same work, then run the same function but this time with minus one and do it again.
Concentrate you’ll understand it, take an example so you can appreciate it.
Still have a problem? Tell me!
No comments:
Post a Comment