This week, we focused heavily on the use and effectiveness on recursion. I certainly have heard of this technique in solving problems before but never really wrapped my head around it until now (although I would say that I am still pretty bad at it). Recursion is definitely very powerful technique if used correctly at the right situations but honestly, simple iterations should be used whenever possible (not over thinking a problem). I was realizing this because as we learned in the first few weeks of class, every single time a method is called, it is put onto a stack and as a result, takes up more memory. In the case of constant recursive calls, it makes a lot of sense that it would create an immense amount of overhead to execute its codes. It would be sensible to avoid recursion as much as possible.
However, I was looking ahead into the course and realize that recursion sometimes prove to be the best thing there is. For instance, traversing a complex data structure like a tree-list requires the need to recursively search up nested-lists. Obviously, anything that could be done recursively could be done using iterations. Unfortunately, it would take an excess amount of confusing loops in order to achieve traversing on data structures.
I struggle a lot with recursion because I tend to think about a problem as a whole as opposed to trying to think of it small (how a problem could be broken down into smaller yet similar problems). The more practice I do, the better I feel I am getting. Hopefully, the practice I have done is enough for me to handle the recursions used for the upcoming weeks where we will learn about link lists, tree lists, binary tree lists etc.
No comments:
Post a Comment