Wednesday, 11 February 2015

SLOG3: Impression about recursion

In this week, we learned a class named "Trees" and designed some methods of it. Those methods all show the idea of recursion for us, which is a really effective way for coding.

The most prior feature of recursion is that it could use itself while executing. For instance, if the variable of the function is a list of list of list, or even more layers of lists inside, and this function are asked to do something towards every single non-list elements, then we could apply the method of recursion, which means that if the function meet a list, it would focus on every items inside the list and if there is another list inside, it would focus on elements inside the interior list, and could execute the procedure above more times until every variable is a non-list parameter. There is no doubt that the length of codes would be reduced effectively via such a method.

Coming back to the Trees class, in such a class, there must exist a single number which is called "node". Besides, there might be a list of numbers or "Trees" called "children", which derive from the "node". As mentioned before, by recursion we could focus on every node easily, and then do some further job like judging whether one number is equal to one of the nodes.

1 comment:

  1. Good Job! I also find the recursion part interesting and difficult. Wish you good luck in the next term test!

    ReplyDelete