Sunday, 29 March 2015

Impressions of Week 9

   This week, my Wednesday night lecture section didn't have class due to the midterm. Therefore,  will discuss the difficulty I had leading up to the midterm, how I solved the problems, and what I thought about the midterm. I'm aware that the Monday lecture covered BSTs, and the insert method. I looked at that method in the lab, and remember finding it confusing. I mainly didn't understand the following lines of code, which happens to be the first few in the method:

def insert(node, data):

    return_node = node
    if not node:
        return_node = BTNode(data)

I was working alone in the library, and ended up asking my friend, who is studying computer science, what exactly the purpose of this statement is. I understand that it's the base case, but I guess the syntax confused me for some reason. All it says, to my understanding now, is that if the node that is passed in is equal to None (ie. node = None), then create a new BTNode object that contains data (which is passed in as a parameter).

I was unsure why we were revisiting this in class, since it is from lab 6, but I suppose Danny didn't want to cover new material, and maybe some other people needed it to be cleared up.

When I was writing my cheat sheet, I wanted to make sure that I understood all the concepts instead of just mindlessly writing them down. I went through all of the labs again and revisited my understanding of things to make sure I hadn't missed any pertinent information. I went over Stacks and Queues, even though Danny said we wouldn't have to know them for the midterm.

I'll lump the following explanation and problem solving into the "Reacts" component of our marking scheme. Lab 5 was a challenge for me. That was the last lab I went to (along with all other students) before the strike. I remember sitting in the lab thinking, "what the heck is going on?" My understanding of recursion was very shaky at that point, and I really didn't understand how to write recursively. So, I took  break after the lab and took a crack at it a couple days later. I worked through it with my friend, who is in computer science. He never told me how to write the methods, but only gave me hints about where I went wrong in my code, and I tried to fix it from there. Something finally clicked then; I understood why the base case was so important. A lot of recursive code in this lab looked the same. The base case was in place to stop it from recurring, under different conditions! I don't know why I didn't understand this before, but it all makes sense now. I wrote all of the methods in lab 5 really easily after that, except for the arity method. This one really stumped me. I went on piazza to see if anyone else knew. Someone posted a solution, but it wasn't correct; he/she threw an arbitrary number into the recursive call in order to have a quick-fix to the problem. I'll admit, it's tempting sometimes, but it only works in specific cases, because it's not logical at all. Originally my code just looked like this:

def arity(t):

 if t.children == []:
        return 0
    else:
        return max([arity(x) for x in t.children]

The recursive part didn't do what it was supposed to, and I was surprised. so, I tried to trouble shoot and look at what had gone wrong. I realized that t.children is a list, and if you take the max of just that list, you are not taking into account the number of children that a node has. So, I then changed the recursive line to:     return max([arity(x) for x in t.children] + [len(t.children)]) . The code then worked perfectly! I submitted my explanation to piazza and corrected the version that the other person had uploaded, and it made more sense to everyone else as well, so I'm happy that I was able to contribute.

After lab 5, I was much more confident with recursion, and lab 6 didn't cause me any problems really. Lab 7 was also pretty straight forward, and I discussed the difficulty I had with it in my last SLOG. So, all I have left is to briefly talk about the midterm. The midterm was fair, I thought. The problem I encountered with the first midterm was that it was marked really harshly with regards to syntax. I hope this doesn't happen again; I regret not submitting a re-mark request, because I clearly understood all the concepts, but was making silly mistakes like accidentally writing 2 ands or 2 ifs, or adding an s where the shouldn't have been one. These mistakes were all due to the time constraint, and nothing to do with my knowledge. Anyways, I thought the first three questions on the midterm were straight forward if you studied inorder, preorder, and postorder, and definitions.  The second last question was difficult, but similar to what was in the lab, so I thought it was decent. In the last question, I was having difficulty knowing where to create new LinkedList objects and traverse the list, and I'm sure it was not completely syntactically correct because I was running out of time. I believe I wrote comments in order to clarify my ideas. I don't know how specifically I am allowed to talk about the midterm, but I'll leave it at that. That's all for this week. Thanks for reading!

No comments:

Post a Comment