Saturday 14 March 2015

Week 9: A conga line, but with nodes

This is a conga line. It gave me the inspiration for the title of this post.

Except nodes don't dance.

Oh, great. Now this song is stuck in my head:



In all seriousness, though, how did we just finish Week 9? Didn't the semester start yesterday?

Exactly.

Anyway, we only had one lecture on mutating binary search trees. Prof. Heap suggested that I add things such as definitions and important lines of code onto my aid sheet. In addition to these, I drew an example of a binary tree and a linked list. I was able to finish in fifty minutes, though more time would be helpful for students to look over their answers for errors, big or small, before submitting their tests.

What I have learned not to do in test situations is aim for a specific mark, say, 100. (I'm not a robot.) This would lead to mental stress, which I have endured a lot when I was around sixteen in grade eleven because of my heightened fear of failure. In spite of U of T, my fear of failure has been reduced slightly from grade eleven. So, Wednesday's test was fair. I was able to stay calm while writing my test.

We've covered linked lists in the past week. (The conga line above may give you a little hint.) A linked list can be defined in two ways:

  1. Lists comprised of an item and a sub-list
  2. Objects, or nodes, that contain a value and refer to the next node in a sequence
According to Prof. Horton, in CSC148, we will look at the second definition of linked lists. I find her slides useful to help me build on my understanding of concepts. They can also be useful for students in all lecture sections. 

Here is how one would visually represent a linked list. (Yay, visuals!)


15 is at the front of the list, and 4 is at the back. We use an "X" to indicate that we've reached the end of the list. In the case of the conga line, arrows point to the next node in the sequence, much like how people link arms with whoever is next in line.

With linked lists, we worked with two classes instead of one: LLNode and LinkedList. Hence, we were taught that a wrapper class represents a linked list in its entirety. So, LinkedList is our wrapper class. (LLNode refers to one node.)

I was extremely confused about this concept, but after looking at lecture slides from both profs and a post on Piazza, I understood how wrapper classes worked.

Speaking of which, Prof. Heap gave my class a gentle reminder not to confuse "wrapper" with "rapper."

404: "rapper class" not found

We also looked at a code generalization when it comes to traversing a linked list. It goes something like this. I've also added comments to help understand what the code does.

cur_node = self.front # start at front of list
while <some condition here>:
     <do something here>
     cur_node = cur_node.nxt # move on to next list
     # end of list: while loop condition becomes False
     # loop exits

For more on linked lists, go here for the Python representation of linked lists.

Also, we did not have labs for the past two weeks due to the TA strike; the profs left us to do the labs ourselves and ask for help when needed. I'll work on Lab #8 soon.

Happy Pi Day, everyone! In celebration of this day, have a picture of a pi(e).


I'll be back for more CSC148 ramblings next week. Stay tuned, and all the best on the last few weeks of school!

1 comment: