Saturday, 4 April 2015

Last impressions (Week 12 SLOG)

Finally, we arrive at the end of CSC148. Looking back at the beginning of the course, I never thought I'd be able to tackle some of the tasks given in the assignment and tests. I remember being daunted by the concept of Python classes in my first lecture, and how the first assignment had no starter code, unlike all previous CSC108 assignments. Those concepts and problems seem trivial now. As the course went by, I found that the freedom in CSC148 allowed me to develop my own coding style, and allowed me to critically think about how a number of functions and methods can come together for one single purpose. Recursion was a big part of the course, and still a tough concept; however, identifying the base cases and careful thinking can unravel some of its mysteries. Not only did we write recursive code, we also saw how recursion can be used to improve efficiency. Tree traversal can often be a long procedure. If we use recursion to "remember" traversed subtrees and their values, we can greatly reduce the time it takes to search for something in a tree. We also looked at recursive data types such as linked lists. Linked lists are unique in that they have instance variables for the front and back node. While I still need time to tinker with linked lists in order to fully understand it, I was shown in lecture that they are not simply an arbitrary class to help CSC148 students with recursive thinking. We were shown its applications in improving the Queue function. Using linked lists, we were able to remove the dependence of n on Queue. In the end, CSC148 was a challenging course for me, as I have very little prior knowledge of programming or computer science in general. However, I am glad that I stuck through the course, as I gained invaluable experience and insight into the field.

Sunday, 29 March 2015

Review an Old SLOG (Week 11 SLOG)

Ah recursion, we meet again. I seem to enjoy writing about this topic, so I shall do so again for this week's entry. Looking back at what seems like an eternity (but truly only 5 weeks!), I can see that I have gained a deeper understanding of recursion. Although the very basic examples of recursive code can be written in a few lines, they do not fully represent the ability of this powerful idea. When I first started tracing recursive code, I never thought that it could be used to represent a type of artificial intelligence. In the assignments, I was surprised that a relatively strong A.I. could be made using recursion. However, the run time proved to be an issue in some code where a large amount of permutations was possible. In our final assignment, we were given an option to explore various ways of improving the efficiency of our recursive minimax code. I agree with myself in the past where I believed that recursion would be a strong tool. Although thinking about it can make my head hurt sometimes, trusting the code seems to help untangle the mess that tracing can sometimes cause. Looking at other classmates' SLOGS, they seem to have issues with tracing as well. The problem with losing track of where you are in your code is a prevalent issue among our class.

Saturday, 21 March 2015

Impressions on Modifying BSTrees (Week 10 SLOG)

Last week we revisited an idea that we had just touched upon: binary search trees. As I had wrote about before, these trees are unique in that each internal node has a maximum arity of two, the data in the nodes are comparable, and the data in the left node is always less than the data in the parent node, while the data in the right node is always greater than the data in the parent node. This specific structure must be conserved when we add or delete nodes from the tree. On the one hand, because humans can view the entire tree in a single instance, we can easily make decisions on which node should go where when modifications occur. Computers, on the other hand, follow a more linear path and can only look at one node at a time, therefore an algorithm must be made for different situations. For example, the algorithm for deleting a node has 5 different scenarios that must be accounted for. I agree with Heap that a good way to go about writing these solutions is to write out what you want your code to do in plain English first. Write comments as often as you can to explain what your code is doing, so that in the future others can understand your code as well. Ultimately, whatever you write in English can be expressed in code.

Saturday, 14 March 2015

Impressions on Linked Data Types (Week 9 SLOG)

Unfortunately, due to the T.A. strike, we had no labs this week, so I had less help than normal with understanding linked lists. However, I still had the chance to go over the lab handout and work on the problems a bit by myself. The idea of a "wrapper" was new and caused some trouble initially. It seemed normal to make a separate class to hold all the linked lists elements, but I found it odd that the wrapper only had variables that referenced the front and back of a linked list. This initially caused me confusion when doing certain tasks such as finding whether a linked list contains a specific object, as I would not know how to access those LLNodes between the front and the back nodes. To solve this problem, I would have to "walk the list," as Heap mentioned; that is, to make reference to the front node, and while a certain condition is satisfied, have that node reference the next one instead. We also worked with mutating a linked list structure, in which the order of actions is very important. In the append example, we were shown that we must change the last values nxt variable first, and then add a node as the back, otherwise we lose the old back node. These linked lists were new to me and I will most likely need to revisit them and tinker with the code once things get settled down over the next few weeks.

Thursday, 5 March 2015

Impressions of recursive data types (Week 8 SLOG)

Last week, we looked at a different type of tree called a binary tree, where each node only has two children. In some ways, the binary tree is simpler than a standard tree, as we can assign variables to the left child and right child, rather than finding a desired node through indexing. Not only does this make writing recursive code slightly easier (in my opinion), but it is also less mind-twisting to think about (again, in my opinion). Additionally, we looked at a type of binary tree called a binary search tree, where the left child node is always less than the current node, and the right child node is always greater than the current node. This makes searching for a particular node much more efficient, as you can effectively reduce your search time in half with the first iteration. In lab 6, we looked at implementing functions using a binary tree. Some of these functions proved to be more challenging as the conditions for desired results were usually more numerous than past exercises. Careful implementation and meticulous testing seem to be vital in order to write functions for these trees, binary search trees in particular.

Thursday, 26 February 2015

Week 7 SLOG

Please mark my Summary of Object Oriented Programming (Week 6 SLOG)

Friday, 13 February 2015

Summary of Object Oriented Programming (Week 6 SLOG)

In the past six weeks I feel that I have gained a decent understanding of classes and basic recursion. Creating our own classes help us solve some problems that would be difficult using only the default python classes. What's interesting about python is that every object stems from the object class, and thus inherit certain methods from it. Even though we can create our own objects (such as different types) de nouveau, they can share a number of properties with other python types. In fact, I learned that we can represent many different problems such as registries, games, and even antiquated mathematical operations using classes. The use of subclasses allows the already flexible idea of objects to fit a greater number of problems. Inherited values and methods allow subclasses have their own identity, while still being related to their parent classes in a way. While completing my assignment, I came across the idea of polymorphism: calling the same method but having it perform different operations. It appeared in my Strategy Class, where I called a method that carried out a move based on the currently chosen strategy. Since the methods had the same name, I could call it in a loop, while only changing the state of the current player's turn. Polymorphism spared me writing additional unnecessary code, and I can see it being a powerful tool.

Speaking of powerful tools, recursion seems to help us solve problems in areas where linear or looped code may have trouble. Not only is it powerful, it is also relatively simple code, with only a base case that is called on the most simple case, and a general case for more complicated arguments. However, these general cases may not always be so simple. In lab 6, I discovered that the general case may span some lines in order to cover every case and achieve the desired result. I think I worry too much about the code executing properly; some days I may attempt to trace out relatively complicated recursive code, sometimes resulting in more confusion. I found that if I just trust that the code will execute properly, I can work with a clearer mind. Interestingly, I have been seeing recursion more and more in my daily life. As a hobby, I enjoy learning about things that sound contradictory to common sense. I learned about fractals a few years ago, but I did not realize that they are based on recursion. Learning about object oriented programming has increased my appreciation for the natural world.