I cannot believe that the course is over. It's been such a long journey. With my initial shaky understanding of a lot of concepts, to the TA strike, to the midterms and assignments, and now the end of the course! I would like to take this time to thank prof Heap, who I think is a fantastic lecturer, and is also a great help during his office hours, and all of the TAs who have helped me, in labs and outside of them. I would like to reflect on my tests, and the labs, as well as my progressive understanding of course content, and what I'm still confused about. The midterms didn't go so well for me. Not because I don't understand the material, but because I don't test well. I have done very well consistently on my assignments, but not my midterms. I got 60 on the first one, mainly due to the time constraint and careless syntax errors due to said time constraint. I really did understand the material, though. On the second midterm, I got 44%. I was shocked when I saw my mark; I really thought I had done much better than that! So, when I got it back, I was relieved to see that my atrocious mark wasn't due to my lack of understanding. On the first question, I needed clarification on what exactly they meant by "arity", and whether that was the number of children for each parent, or the maximum number for each parent. I have seen the definition go both ways, and wasn't sure. Since we didn't have TAs in the room, I couldn't ask, and I was deducted marks where I clearly understood the concept. For the second question, I traced over the diagram in the correct order, instead of writing down the values, because this is what we had done in class, and I guess I didn't read the question as thoroughly as I should have. Anyways, my work was completely correct based on what I'd done, and I should not have been penalized, and gotten 0 on that question. On the last question, I knew exactly what to do, and I'd written it out in the comments, but I was so rushed for time I started jumbling all my ideas, and it came out as one incoherent blurb. I'm going to redo that question, to make sure I actually understand it.
As far as the labs, I have done all of them, aside from the last two, because I've had a lot of work to do. I found the labs to be really helpful practice; I didn't do well on the lab quizzes. I was in the hospital 3 times during the course of our first 5 labs, and they were stressful for me, especially since I was ill. I should probably apply for special consideration. I understand recursion much better than I initially did, thankfully. A3 really helped with that. I'm going to re-do the labs that have to do with classes; I remember having trouble writing __init__ methods, and knowing what to put as parameters. We'll see if that's still the case. I'm still a bit shaky on the concept of O(n). I believe it has to do with the run-time of a function. I also find difficulty in how to know when a function is dependent on certain variables, and how the run-time is affected accordingly. I don't know if we did best and worse case run-times, but I found a really good table on line that kind of helped me understand big O a little more. The link is here: http://bigocheatsheet.com . I need to re-do all of the labs and past exams in order to practice for the final exam; I'll be doing this next week after my calculus exam. To wrap things up, I really felt like I learned a lot in this course, and I really enjoy programming. In the future, I want to do a comp sci minor; I hope that I get into the program! I'll keep working hard! Thank you for reading my blogs, and good luck to everyone!
Monday, 6 April 2015
Assembling the Sub-calls of My Knowledge About Recursion: AKA, YAY! I learned Something.
For week 11, we were asked to revisit one of our previous posts. Since recursion is a large component of the course, and it is probably going to come up a lot in the future, I shall revisit my previous post about recursion. Initially, I mentioned that recursion occurs when a function "calls itself", and that the base case terminates the recursion. While I agree with these statements, my understanding of recursion at that point was very shallow, as we had just started to learn about it. While I agree with my earlier points, I would also like to add to them. I mentioned that recursion looks a lot more concise that using loops (i.e.. for loops). However, as I discovered in A3, recursion isn't always as simple as a single line list comprehension that does the job for you. To elaborate, in my previous post about recursion, I mentioned that I was having trouble with a recursive call in the form of a list comprehension: ie. 1 + max[some_function(x) for x in t.children]. The function that I was referring to was the height(t) function from lab05. It looks like this:
def height(t: Tree):
''' (Tree) -> int
Return 1 + the number of nodes in longest path in Tree t.
'''
if t.children == []:
return 1
else:
return 1 + max([height(x) for x in t.children])
The reason I was having difficulty is due to the fact that I didn't fully understand how the sub-calls get assembled, and where the base cases are combined with the results from the recursive calls. (When I wrote my original post about recursion) Now, I have a better understanding through countless hours of mental breakdowns and practice. Each recursive call goes into a sub-call, until the base case is reached. The results from each call are then propagated back up the tree and combined, in order to create one final, comprehensive result. Each time a recursive call goes into yet another sub call, that function call is "paused", until the result from the sub-call is returned. The computer knows exactly where the recursive call was on hold, and this is why it knows how to assemble everything correctly based on your code and your base-case. I had a really hard time understanding this, but I am more comfortable with it now. Now, back to my argument that recursion isn't always a simple one line expression, I will use A3 as an example. There was a function in A3 called branching_stats, that needed to be implemented for option B. I'm not going to post my code here, because there are people that may not have handed in the assignment yet due to extenuating circumstances (such as myself), but I will speak of it in a general sense. Branching_stats required you to return a dictionary of arity to number of nodes with that arity. I guess you could call it a "dictionarity". HA. HAHAHA. Sorry. Bad pun. Anyways, for this function, not only did I have to implement a recursive call and store it in a variable, that recursive call was in a for-loop. And there were other for loops and a bunch of if and else statements as well. So, this function uses recursion, but it also uses loops as well. At least, that's how I implemented it, vaguely.
Now, to compare my SLOG to other student's SLOGs, I will say this first: I did not see anyone else write about tail-call optimization. So, I'm proud of myself for that, and I definitely stand by what I said. I've chosen to compare my understanding of recursion to 3 other classmates' understanding. The first person I've compared with has the blog domain:
http://beyoncepadthaiismywarriorname.blogspot.ca
We have been partners for all 3 assignments, so I thought it would be interesting to see what we both initially thought of recursion, and how much we've progressed, since I know that we've both been struggling with it. So, I read her post about recursion, and it seems that her understanding was either worse than mine, or she didn't have much to say about recursion at that point. All she said about it was that recursion is when a function calls itself. This is true; I'll give her that! I know she has progressed her understanding from that as well, just like I have. She hasn't written this weeks post yet, so I don't know what she'll have to say about recursion now.
Okay, for the other two SLOGs I'm going to be talking about, I'm not going to lie. I picked them based on the fact that their URLs sounded cool and creative. But they also had insightful things to say that I thought were comparative to my knowledge.
I was happy to see that the blogger behind the following SLOG wrote posts as long as mine:
http://allthemontypythonjokes.blogspot.ca/search?updated-max=2015-03-09T10:13:00-07:00&max-results=7
This person didn't really describe what recursion was, but stated that he/she got better at it with practice in the labs. I felt the same way; the labs were really helpful for understanding recursion. And, he/she also stated that recursion seemed fairly simple, like I initially thought, until he/she realized that he/she would rue those words when the functions got more complicated. The exact same thing happened to me. The blogger also spoke about how tracing recursion helped with his/her understanding. I should have done this more, in retrospect, because I may have understood how sub-calls are assembled sooner. The blogger hasn't written this week's post yet either, so I can't see what his/her understanding is like now, in comparison to my own.
My final comparison is to the following blogger's posts about recursion:
http://gamer-born-programmer.blogspot.ca
Initially, he (I'm using "he" now for simplicity's sake) thought that recursion was very difficult, and had a bare minimum understanding of it. It seems like he had less of an understanding than me. However, he did mention that he had a hard time wrapping his head around how the function calls itself. I had trouble with this too. I understood the concept and how it worked, but I always got stuck on the thought, "What if my function doesn't work? How can it call itself? The function isn't even finished being written yet before it calls itself!" Now I understand this concept. Firstly, you have to trust yourself and assume you've written the function properly, and it returns what it's supposed to. I never trust myself, so I had a lot of trouble doing this. Secondly, even though the function looks like it's not done, it is. The base case stops the recursion and propagates the results back up the tree combinatorially, and the computer knows exactly where each claws paused, and executes it from there. So, in short, trust yourself. In A3, I trusted that my function did what it was supposed to and returned the correct type, so I could store it in a variable and use it later and assemble it with all of the other components returned by the recursive call. I'm staring to be more confident with myself! The blogger of this SLOG, in this week's post, mentions that he used recursion in A3, and he now has a much better grasp on it, which is similar to my experience as well!
That's all for this week- thanks for reading!
def height(t: Tree):
''' (Tree) -> int
Return 1 + the number of nodes in longest path in Tree t.
'''
if t.children == []:
return 1
else:
return 1 + max([height(x) for x in t.children])
The reason I was having difficulty is due to the fact that I didn't fully understand how the sub-calls get assembled, and where the base cases are combined with the results from the recursive calls. (When I wrote my original post about recursion) Now, I have a better understanding through countless hours of mental breakdowns and practice. Each recursive call goes into a sub-call, until the base case is reached. The results from each call are then propagated back up the tree and combined, in order to create one final, comprehensive result. Each time a recursive call goes into yet another sub call, that function call is "paused", until the result from the sub-call is returned. The computer knows exactly where the recursive call was on hold, and this is why it knows how to assemble everything correctly based on your code and your base-case. I had a really hard time understanding this, but I am more comfortable with it now. Now, back to my argument that recursion isn't always a simple one line expression, I will use A3 as an example. There was a function in A3 called branching_stats, that needed to be implemented for option B. I'm not going to post my code here, because there are people that may not have handed in the assignment yet due to extenuating circumstances (such as myself), but I will speak of it in a general sense. Branching_stats required you to return a dictionary of arity to number of nodes with that arity. I guess you could call it a "dictionarity". HA. HAHAHA. Sorry. Bad pun. Anyways, for this function, not only did I have to implement a recursive call and store it in a variable, that recursive call was in a for-loop. And there were other for loops and a bunch of if and else statements as well. So, this function uses recursion, but it also uses loops as well. At least, that's how I implemented it, vaguely.
Now, to compare my SLOG to other student's SLOGs, I will say this first: I did not see anyone else write about tail-call optimization. So, I'm proud of myself for that, and I definitely stand by what I said. I've chosen to compare my understanding of recursion to 3 other classmates' understanding. The first person I've compared with has the blog domain:
http://beyoncepadthaiismywarriorname.blogspot.ca
We have been partners for all 3 assignments, so I thought it would be interesting to see what we both initially thought of recursion, and how much we've progressed, since I know that we've both been struggling with it. So, I read her post about recursion, and it seems that her understanding was either worse than mine, or she didn't have much to say about recursion at that point. All she said about it was that recursion is when a function calls itself. This is true; I'll give her that! I know she has progressed her understanding from that as well, just like I have. She hasn't written this weeks post yet, so I don't know what she'll have to say about recursion now.
Okay, for the other two SLOGs I'm going to be talking about, I'm not going to lie. I picked them based on the fact that their URLs sounded cool and creative. But they also had insightful things to say that I thought were comparative to my knowledge.
I was happy to see that the blogger behind the following SLOG wrote posts as long as mine:
http://allthemontypythonjokes.blogspot.ca/search?updated-max=2015-03-09T10:13:00-07:00&max-results=7
This person didn't really describe what recursion was, but stated that he/she got better at it with practice in the labs. I felt the same way; the labs were really helpful for understanding recursion. And, he/she also stated that recursion seemed fairly simple, like I initially thought, until he/she realized that he/she would rue those words when the functions got more complicated. The exact same thing happened to me. The blogger also spoke about how tracing recursion helped with his/her understanding. I should have done this more, in retrospect, because I may have understood how sub-calls are assembled sooner. The blogger hasn't written this week's post yet either, so I can't see what his/her understanding is like now, in comparison to my own.
My final comparison is to the following blogger's posts about recursion:
http://gamer-born-programmer.blogspot.ca
Initially, he (I'm using "he" now for simplicity's sake) thought that recursion was very difficult, and had a bare minimum understanding of it. It seems like he had less of an understanding than me. However, he did mention that he had a hard time wrapping his head around how the function calls itself. I had trouble with this too. I understood the concept and how it worked, but I always got stuck on the thought, "What if my function doesn't work? How can it call itself? The function isn't even finished being written yet before it calls itself!" Now I understand this concept. Firstly, you have to trust yourself and assume you've written the function properly, and it returns what it's supposed to. I never trust myself, so I had a lot of trouble doing this. Secondly, even though the function looks like it's not done, it is. The base case stops the recursion and propagates the results back up the tree combinatorially, and the computer knows exactly where each claws paused, and executes it from there. So, in short, trust yourself. In A3, I trusted that my function did what it was supposed to and returned the correct type, so I could store it in a variable and use it later and assemble it with all of the other components returned by the recursive call. I'm staring to be more confident with myself! The blogger of this SLOG, in this week's post, mentions that he used recursion in A3, and he now has a much better grasp on it, which is similar to my experience as well!
That's all for this week- thanks for reading!
Subscribe to:
Posts (Atom)