I've tried to make a habit of, after writing a test, analysing what went right and what went wrong. Overall the test ended up being exactly what I expected and I'm confident that I did well. I studied the right topics and I had a good understanding of everything I studied. As for what went wrong, at first I did not properly read what the last question was asking for. It asked us to write the body of a method that inserts a new node in between the second last and the last node of a linked list as well as change the value of the last node. However, instead of just editing the value of the last node I created entirely an entirely new node. This probably sounds pretty minor but in combination with everything else we were asked to do for this question it made my code far more disorganized and error-prone. When I saw this was happening I went back to reread the question and noticed that there was no reason to create a new node. I drew a big X through everything I had written and somehow managed to finish rewriting the method in the final 5 minutes of the test. For future tests, I'm going to take a bit more time to read questions carefully. In this case, skimming through a question cost me much more time than it saved.
As a side note, I really enjoyed the style of lab 8. While the other labs gave us methods and functions to write, the purpose of lab 8 was to explore and experiment with some complex code (in this case the BST delete method) and work out ways to improve it. I think the instructors did a great job altering the labs in order to accommodate the ongoing strike. Lab 8 really lead me to an in-depth understanding of the delete method when at first I had a lot of trouble it seeing how it worked.
Thursday, 19 March 2015
Sunday, 15 March 2015
Week 8: Linked Lists
I found working with linked lists to be a very fun and productive challenge. While initially learning about them in lecture my first impression was that implementing linked list methods was going to be extremely straightforward. They have two parameters and a linear arrangement, how hard can it be? But once I started writing methods for lab 7 I realized that iterating over a linked list properly wasn't quite as trivial as I thought it would be. When I first began writing these methods my instinct was to use for loops. I don't remember exactly what the conditions or the bodies of these loops were but I noticed that as the methods became more demanding my code was becoming very ugly. I was able to simplify things by using break statement but in both CSC108 and CSC148 the use of break has been highly frowned upon. I felt that there should be a simpler strategies for implementing these methods. Eventually I was able to get all doctests passed but I was still dissatisfied with the aesthetic dimension of my code. I like my code to be as lean as possible. This improves its readability but I also view elegance in code as preferable for it's own sake. Given two equally effective solutions to the same problem, I would rather go with the more elegant one.
A few days later the solutions to lab 7 were released and I saw that the instructors used while loops to accomplish any iteration in linked list methods. I saw that this resulted in code significantly more simple and readable that what I had written and I was a bit disappointed in myself that I never thought to experiment with while loops. I only looked at the solution to the first couple of methods and I immediately began recoding all of lab 7 on my own with while loops. I was much more satisfied with the result this time around. I suppose this experience helped me become a bit better at problem solving. From now on I'm going to make a stronger effort to consider all tools I have at my disposal in order to come up with more simple solutions.
Thursday, 12 March 2015
Week 7: Abstract Data Types
A couple years ago, prior to studying CS, I took a statistics course which contained a particularly outspoken CS major. During one class I heard him say to an acquaintance how in CS he had encountered some extremely abstract material. This comment really caught my attention. Studying abstract topics is something I really enjoy, but at that time I had no knowledge of CS or of programming in general so I wasn't sure what he meant. Now that I have some experience with abstract data types I have a much better understanding of what he was getting at.
There are an indefinite number of ways of storing data and accessing data. Many of these are extremely useful and I find it amazing that it's possible to instantiate their structure by using a programming language. These ADTs end up being very versatile tools in a programmer's arsenal, even ones as simple as a queue.
For lab #5 (trees) we were asked to implement a method which returns a list of all values contained in the nodes of a given tree. At the time I felt that the most natural way to traverse the nodes was by using what I later found out is called a breadth-first search (http://en.wikipedia.org/wiki/Breadth-first_search). I knew that I could use recursion to easily implement the method but this would return a list with the values in a different order and for some reason I had my heart set on a breadth-first approach. Recursion didn't seem that suitable so I spent some time considering how I might solve this problem. Before too long I realized that I can add the root to a queue and while the queue isn't empty, repeat the process of dequeue-ing whatever is at the front, adding its value to the list to be returned and then enqueue-ing all of its children. This algorithm ended up producing a list of values in the order I wanted.
If I had no knowledge of the queue ADT I either wouldn't have been able to solve this problem or my solution would have been significantly more complicated. Different situations call for data to be structured in different ways. In this case, having knowledge of a first in, first out approach to organizing and accessing data is what lead me to a clean, straightforward solution to this problem.
There are an indefinite number of ways of storing data and accessing data. Many of these are extremely useful and I find it amazing that it's possible to instantiate their structure by using a programming language. These ADTs end up being very versatile tools in a programmer's arsenal, even ones as simple as a queue.
For lab #5 (trees) we were asked to implement a method which returns a list of all values contained in the nodes of a given tree. At the time I felt that the most natural way to traverse the nodes was by using what I later found out is called a breadth-first search (http://en.wikipedia.org/wiki/Breadth-first_search). I knew that I could use recursion to easily implement the method but this would return a list with the values in a different order and for some reason I had my heart set on a breadth-first approach. Recursion didn't seem that suitable so I spent some time considering how I might solve this problem. Before too long I realized that I can add the root to a queue and while the queue isn't empty, repeat the process of dequeue-ing whatever is at the front, adding its value to the list to be returned and then enqueue-ing all of its children. This algorithm ended up producing a list of values in the order I wanted.
If I had no knowledge of the queue ADT I either wouldn't have been able to solve this problem or my solution would have been significantly more complicated. Different situations call for data to be structured in different ways. In this case, having knowledge of a first in, first out approach to organizing and accessing data is what lead me to a clean, straightforward solution to this problem.
Subscribe to:
Posts (Atom)