Thursday, February 5, 2015

Week 5: Tracing Recursion

We've finally been introduced to the concept of recursion last week! Looking at recursive code for the first time, I found it quite hard to comprehend. This is because even though I've seen functions call other helper functions before, I haven't seen a function call itself! And this is precisely what recursive functions do!

I found that tracing recursive functions on paper was extremely helpful in understanding how recursive functions work. Going through the activity sheet we were given in class showed me that having a function call itself doesn't seem completely ludicrous at all. It actually makes a lot of sense!  This activity also highlighted the importance of having a base case in order for the recursion to work. Furthermore, I noticed that recursive code itself is quite short. It's amazing how this short piece of code can be so powerful!

  

1 comment:

  1. I've enumerated in my SLOG that tracing can also be used to actually write the recursion when you get stuck on some problems. I believe base cases become evidently more important when we get to recursing through data structure methods of trees, heap, etc.

    ReplyDelete