Sunday, April 5, 2015

Week 12: Looking Back



Over the past 12 weeks, we have learned many broad central themes in programming. It has been a fun and insightful experience and I have learned a new way of thinking about problems. Some of the core themes that we have covered are ADT’s, OOP, Trees, Binary Trees, Binary Search Trees, Linked Lists, Recursion, Inheritance, Properties, Test cases, and Big Oh. These are just a couple of the topics we covered this semester, a few that came to mind.

Our assignments were really fun, challenging, and time consuming to complete, but they were worth it. I am currently in Life Science and out of all of my courses, this one made me think the hardest. It is one of the greatest feelings when I finally get a function working after a few days of working on it. It is even better when I can see how to cut a function down from 20+ lines to 5 lines of code. I enjoyed how there was a lot of overlap between central themes in this course and the synergy helped me cement the concepts in my mind. Sometimes a problem that seems really complicated is actually really simple once enough thought is put into it. When I am studying for other classes, I sometimes catch myself thinking in a very pythonic way because sometimes it is easier to understand. I think that computer programming is something that I enjoy learning about and I plan to complete at least a major in it during my time at UofT.

Thursday, April 2, 2015

Week 11: Recursion revisited




I am choosing to revisit Week 5’s slog about Recursion because I think that I have a lot to add to it. Recursion was one of the central themes of this course and most of our assignments required recursive thinking to complete. I chose option B for Assignment 3 because I wanted more practice writing recursion. When I first learned about recursion it was hard to understand how the function calls itself without breaking. I was confused because I kept thinking “If it calls itself how can the function be complete?” and I didn’t find the answer to that question until I sat down and traced a function that used recursion.

Recursion works by having a case that is so simple that it can be solved without having to call itself. This is essential, because if there is no base case, the function will have an infinite loop and it will never stop calling itself. From understanding this, it is helpful to realize that every time the function calls itself, it is trying to get to the base case. If it doesn’t reach the base case, it will never work. Tree structures are inherently recursive because as the function traverses the nodes, it eventually reaches a leaf which is a perfect base case.

Sometimes in order to write a recursive function, the function needs more information than what is being passed into it. This is when it is useful to create a helper function has additional parameters so that it can do the bulk of the work and update its local values in the main function as it “digs deeper” to get to the base case.

Tracing recursion is important because it helps us understand recursion without “looking under the hood” at how the computer does it. Before I try writing recursion, I plan pieces of my function by asking myself questions like “What is my base case? How can I make the problem smaller? Do I need extra parameters? Do I need to update values that I get from levels of recursion?” to create a blueprint of my code. These questions help me understand what I want my function to return and how I can accomplish what I want it to do. Planning ahead has helped make my code look cleaner.