Saturday, February 7, 2015

Tracing Recursive Code (Week 5)

As I had said last week, recursion was a new subject to me. My computer science teacher in high school never even mentioned about recursion. The only thing that I knew about recursion at the start of this course was that Google search easter egg where if you search recursion it says "did you mean: recursion". Moving on, I find that recursion really makes code look simpler but a bit more complicated. I have noticed that all the recursive code that we have traced so far always includes an if structure. I wonder if it is possible to design a recursive function that doesn't use an if structure and doesn't run into an infinite loop.

Anyways, onto tracing recursive code. I didn't really understand the first recursion tracing handout that the professor gave in lecture. Well, I just simply followed along and wrote down whatever was on the screen. When lab03 came around, I decided not to bother with looking at it until the day of the lab. During the lab, I noticed how simple and similar the example tracing were to the first handout. I immediately used the first handout to help me complete the first few lab questions. The recursive code without proper docstrings weren't very different, since I don't always pay attention to docstrings anyways. Tracing these recursive code suddenly seemed so much easier. However, recursion still appears to me as simply a way to complicate and beautify code.

Also, that last question on implementing that length function using recursion was difficult for me. I tried all sorts of ways to do it but failed. Mainly, I was unable to compare the length of the current list to that of each sublists, thus I was only ever comparing the deepest sublists. I eventually gave up on it. It was probably the first time I ever gave up on completing a piece of code. I asked a friend to help explain it to me, which was very helpful. I will try harder next time.

No comments:

Post a Comment