So I've written about recursion before, but now I think I understand it a lot better. After reviewing the recursive functions from class examples repeatedly, I can confidently break down what recursion actually means.
Recursion involves a function calling itself. However, there is always a base case, where there is no recursion involved. For example, take a look at the nested_depth function:
Here, the else clause is the base case. If L is an int, no recursion is involved, and 0 is returned. Recursion happens when there are lists, so if I have L = [1, 2, [3]], the function will go through the entire list before returning a value. Since L is a list, it will return 1. The first element of the list is 1, which is not a list, so it will return 0. Next, 2 is also not a list, so it returns 0. The next element is a list, which will add 1. for a total of 2. Now that the function has reached the end of the list, it will return 2.
Tracing through examples, starting with the base case, is very helpful because once I know the output of a simpler example, I can apply it to a more complicated example.
Thursday, 27 February 2014
Sunday, 16 February 2014
Week 6: Tree ADTs
This week we looked at Tree ADTs, and I think they helped me better understand recursion. I'm still having a little bit of trouble writing recursive functions myself, but attempting to write functions for pre-order, post-order, and inorder helped me in a couple of ways: first, I practiced writing list comprehensions, and I increased my understanding of recursion.
I think what really helped this week was the lab that we did this week. It was a relatively short lab, but we still took the whole time because we really wanted to take our time to understand the recursion behind the functions.
I am still a little confused about namespaces and scopes, but there was this post on http://aheapofpythons.wordpress.com/ that helped me understand it a bit better. I think I work by myself too much at times. In 108, I did all the assignments on my own, and I always did the worksheets in class on my own. In 148, the only time I ever work with people is during the labs. I've realized that it helps a lot, and now reading other people's blogs, I will definitely make an effort to ask other people for help if I need it.
I think what really helped this week was the lab that we did this week. It was a relatively short lab, but we still took the whole time because we really wanted to take our time to understand the recursion behind the functions.
I am still a little confused about namespaces and scopes, but there was this post on http://aheapofpythons.wordpress.com/ that helped me understand it a bit better. I think I work by myself too much at times. In 108, I did all the assignments on my own, and I always did the worksheets in class on my own. In 148, the only time I ever work with people is during the labs. I've realized that it helps a lot, and now reading other people's blogs, I will definitely make an effort to ask other people for help if I need it.
Friday, 7 February 2014
Week 5: More Recurision and Namespaces
This week we looked into recursion for Step 5 of Assignment #1. In theory, it makes sense to me. I tried running it through the python visualizer, and honestly it was a bit of a mess in my mind. The steps were going all over the place. At least, that's what it looked like. I'm going to go back through simple recursion functions to make sure I understand the concept fully. Even though we did a recursion lab this week, I probably let my partner do more work than I should have. I was able to follow what she was doing, but writing the functions myself is a lot different. I need to be able to write some myself first. Only then will I write the recursive function for four stools.
On Wednesday, we went over namespaces. Words like local, non-local, global, and inner scope come to mind, but I don't know exactly what they mean. I wasn't entirely able to follow what was going on in class, so I definitely need to review that more. Someone else wrote "I learnt from this class that the class readings and lecture notes are so crucial to this course" (from http://endwithcolon.blogspot.ca/, if you're interested). It's a good point, and it seems obvious, but I haven't been keeping up with the course material as much as I did with 108. I really liked the inverted classroom format last semester, and I wish we had that, but I understand that as I advance in my computer science career, there won't always be structure. Maybe the freedom could be good too. It will give me a chance to discover my learning style (although I think I know how I learn best already) and try new things.
On Wednesday, we went over namespaces. Words like local, non-local, global, and inner scope come to mind, but I don't know exactly what they mean. I wasn't entirely able to follow what was going on in class, so I definitely need to review that more. Someone else wrote "I learnt from this class that the class readings and lecture notes are so crucial to this course" (from http://endwithcolon.blogspot.ca/, if you're interested). It's a good point, and it seems obvious, but I haven't been keeping up with the course material as much as I did with 108. I really liked the inverted classroom format last semester, and I wish we had that, but I understand that as I advance in my computer science career, there won't always be structure. Maybe the freedom could be good too. It will give me a chance to discover my learning style (although I think I know how I learn best already) and try new things.
Subscribe to:
Posts (Atom)
