{
if(counter == 0)
return;
else
{
System.out.println(""+counter);
myMethod(--counter);
return;
}
}
(source - http://danzig.jct.ac.il/java_class/recursion.html)
As we can see, this recursion is not infinite, it is essentially a loop. When should we use recursion to solve problems? We use recursion when we can see that our problem can be reduced to a simpler function to be solved.
Now lets talk about the characteristics of recursion:
1. Every recursion function should have a simple base case that is the final reduced solution, and of course a return value.
2. A very sophisticated problem set that is intended for recursion to happen.
3. A recursive call which passes the simpler problem back into the method.
Now we have discuss about recursive functions, I came to a better understanding of recursion. Throughout these weeks, I learned how to solve recursive programming, how it works, and how to make such functions.
I will continue to practice recursion, because I know it is very important in not only python, but it is also very important in other programming languages.
As we can see, this recursion is not infinite, it is essentially a loop. When should we use recursion to solve problems? We use recursion when we can see that our problem can be reduced to a simpler function to be solved.
Now lets talk about the characteristics of recursion:
1. Every recursion function should have a simple base case that is the final reduced solution, and of course a return value.
2. A very sophisticated problem set that is intended for recursion to happen.
3. A recursive call which passes the simpler problem back into the method.
Now we have discuss about recursive functions, I came to a better understanding of recursion. Throughout these weeks, I learned how to solve recursive programming, how it works, and how to make such functions.
I will continue to practice recursion, because I know it is very important in not only python, but it is also very important in other programming languages.
No comments:
Post a Comment