Sunday, March 9, 2014

Week 8: Trees, Recursively Defined Structures, and more



After a busy weekend, I finally have the time to sit down and collect my thought for this week. I would like to this opportunity to talk about trees and linked lists, including the assignment, labs and exercise relating to this topic.
Last week’s tutorial on the implementation of a Queue class for LinkedList was disappointing to say the least, with almost everyone in my section dumbfounded at the end with little to nothing accomplished due to the confusion in the instruction. Since then, I have learned a lot more about tree structure and the implementation of these structures in different forms. This week’s lab was a continuation of the last, where we have to write functions for LinkedList class. As I discussed in my earlier posts, recursion was very tricky to handle and implement; after much practice in this course and theory computation, I find recursion to be second nature now, where I would be able to think in terms of recursion pretty quickly given a problem. Some harder ones take a lot longer to think through, but once work through the recursive steps; I find it really easy to put that into python code. This is especially the case in the lab, where I was able to complete all the functions right after another, including copy and filter, which were all recursively defined.
Exercise 3 was very interesting to do as well, it was hard to visualize at first, but once figure out the solution, I was easily able to write out the recursively defined functions. One thing I want to make a note to myself after doing exercise 3 is to be careful in which order I write out my list comprehension. I now make sure to put the base case first because it would produce an error to do something to base case. What I mean is something like this:
[] if this = [] else do_this(this[0])      instead of      do_this(this[0]) if this != [] else []
If I were to put it the other way around, as I did initially in the exercise, it would produce mostly an index error was it is evaluated from left to right. I had a lot more problem in part b, as I wanted both the depth and sum of the path, but it was hard to find max of both and compare. I found it easier to use the max function on a tuple as it compares the first element first, then the second, so the result will be the highest sum of those trees with deepest depth.
I also started part 2 of assignment 2 this week, where I am trying to determine whether a given string is a valid regex. It is very challenging at the moment as I have not yet derived an algorithm to parse a regex, I am pretty sure I will figure it out soon and talk more about this next week.
Furthermore, I was going through some slogs posted by other students, Brian’s slog (http://my148slog.blogspot.ca/2014/03/brians-csc148-slog-8_5.html) this week talks about his challenges in this course which interest me, as I have faced similar problems in the past and still do to this day to a certain extend. I would say I have gotten pretty good at recursion and comprehension lately; this is mainly due to the fact that after given an assignment, if a problem can be solved using recursion and/or list comprehension, I would do that or at least try my hardest to do it that particular way instead of an “easier” method, it really helped me understand a particular method of programming and I hope this tip can be helpful to others as well. Overall, the only problem with computer science at the moment for me is the theory(CSC240), which is what I’ll be focusing on for now, with more understanding in the theory of computation, I’m sure I’ll be more comfortable in this course as well.

No comments:

Post a Comment