During the last weeks, we
learned about recursion.
Recursion is a recursive
method or class which calls the method itself inside the method. Take trees for
example, if we want to get the total value of all nodes, we have to go through
each node. In order to do this, we need to start from the root, and all the
value of the current node to the total count, and if the current node have
children, we call the method again on its children, and so on. This method will
go on and on until it went through all the nodes, and we will get an accurate
total value of all the values inside the tree.
When we use recursion in our
methods, we usually use it alone with “while” or “for” loops, because recursion
is a continuous idea. Recursion is usually used on object which its solutions
is based on similar smaller objects. I think that recursion is a very important
idea in computer science, and mastering it will help me a lot in future
computer science studies.