Wednesday, March 5, 2014

W8: LinkedLists

Although it is confusing, I enjoyed learning the two methods of thinking about LinkedLists. However, while the distinction between the two methods seems crystal clear as the prof explains it in class, sitting alone before my computer, it suddenly becomes difficult to distinguish them.

So first, before I reflect on LinkedLists, a short note on the two methods (see link):
1) This is the "list within a list" structure, where a LinkedList has a "head" or "value" and the rest of it, which is also a LinkedList. A format like this is useful, because each list has is the same and so the same operations can be performed on them.
2) The "node and reference" structure, where a LinkedList is more like a chain. Each chain is node, that contains a value and a reference to the next node. This format is useful because a programmer doesn't delve layer by layer into the list, but rather jump from node to node.
Right now, I think I'm more familiar with the first method, just because we've been focusing a great deal on recursion and the nested lists idea goes way back to the first weeks of this semester. However, I'm getting the feeling that the prof leans more towards the second method, which I must admit, seems like it'd been easier if only I could master it.

Though I'm not quite there yet, I am slowly understanding both methods better (the lab tutorials are extremely challenging but informative). Also, did I mention how much I've come to appreciate tuple unpacking?! It comes back full force with LinkedLists, and finally I've understood why a programmer would do tuple unpacking rather than conventional line by line variable assignments. If you do separate variable assignments, its possible that a value (especially in a mutable class) has changed before you assign it. However, with tuple unpacking, the left side of the equation symbol is evaluated first, and then assigned to the right side. MAGIC!


No comments:

Post a Comment