Matrix

Sunday, 22 March 2015

Assertions, Unit Tests, and A2

This week's focus was on unit tests, revisiting A2 and using deep copies, and assertions.

The problem with A2 is that testing for all cases was extremely difficult to do. This was because the strategy was based on randomness and probability. There was always a certain degree of uncertainty as to whether the code worked or not because it simply could have randomly chosen the correct answer without actually applying the strategy. For each test case, there is a probability that it passes the test case based upon the random strategy. But take multiple test cases and multiply the chances of the case passing based on randomness becomes smaller and smaller. So for example if test 5 test cases all had a 50% chance of passing and the 6th had a 20% chance of passing, that means that the probability of all the cases passing from randomness is only 0.00625%. This ensures that you feel a lot safer knowing your code almost certainly works and not just based off the randomness factor. This was a very important concept to learn to minimize the chance of error in your code. This proves that choosing good test cases and having many of them are very important in ensuring your code runs smoothly.

The other things we learned were implementing unit test cases and deep copies. We touched on unit tests briefly since most of the class who had taken CSC108 had experience with unit tests. We learned about deep copy and how it was important in A2. Having a copy at every level of your program ensures that GameState is never changed. My partner and I had already implemented a sort of deep copy in A2 so this was not something new.

On Wednesday we learned more about assertions in unit test cases. Assertions help state what we know is true at a certain point in the code and also at the beginning of the code. Assertions raise an error if the certain condition fails. This part of unit tests are very important as they point out the mistakes to you or someone else editing your code. It points out important bits of knowledge that could be useful during coding and also in the future (during updates). There aren't really any downsides to assertions so you should use them frequently. I found this part to be very useful since it will become a great time saver for code you need to continuously maintain and update.

Don't slack off! Write some unit tests!

Monday, 16 March 2015

Week 9: Term Test 2, BST Mutation

This week was shortened by the second term test and we briefly discussed mutation of binary search trees on Monday. I found the second term test to be fair and I think I did well.It covered binary trees, some recursion, and linked lists. Like the first, it required you to study the labs throughout. Hopefully, the TAs will finish the strike soon so we can get lab practice again.

We were given a handout about binary search tree mutation in the lecture. It involved writing a binary search tree, looking at the key elements of it (class BTNode and class BST), and then implementing some mutation using the insert and delete functions. It was a relatively easy exercise and didn't take long considering I had spent the last two weeks studying binary trees for the term test.

We did some basic review for the term test on Monday as well. We looked over some labs, discussed the test, and reviewed key concepts. It was a fairly straightforward lecture and was to be expected considering the other half of lectures that week would be composed of the term test.


Saturday, 7 March 2015

Week 8: Strikes, LinkedLists, and Mutating

This week did not have a lab due to the unfortunate timing of the TA strike. Nonetheless, I worked on the lab at home and went to the lectures. Without the help from the TAs and the lab environment, the concepts taught this week were obviously more difficult to understand. The central focus of this week was linked lists, how to manipulate them, and how to traverse through them.

Basic structure of the linked list

Linked lists are essentially a linear sequence of nodes. A linked list can be seen in two ways but the way we focused on during lecture was viewing it as a sequence of nodes, each with a value and a reference to the next node. The primary benefit of using linked lists is that it allows you to easily insert or remove list elements without shifting the whole structure. Values can be added or removed at any point in the list.

We also took a quick look at some pseudo code to help understand how moving through a linked list works. We also took a look at mutating linked lists. Mutability of lists is something we explored in CSC108 where the contents of the list can be changed. Our professor explained the basic concept and will expand more about mutability into trees and such in the coming weeks.

Not this kind of mutating
Overall, this week was not very hard to learn and understand. The tricky part was obviously tackling the lab by myself but I managed to figure it out at the end. Linked lists are an important concept to learn because it seems like a very efficient way to add/delete instances of list elements. This seems useful in real life computing where time predictability is important. It also seems to leave more room to grow as you don't necessarily need to define the size of the list from the get go. Compare this to something like an array where you need to re-declare and copy the elements if the array gets to big, and it becomes a very useful tool in saving time. Hopefully the strike doesn't last too long and we can get back to learning in the labs as well.

Saturday, 28 February 2015

Week 7: The Return of Recursion

So as reading week ends and class starts up again, we are told to write a summary about a key concept that we have learned. I chose recursion because I struggled with it in labs and on the midterm so naturally I studied it the most afterwards. 


So what is recursion exactly and why is it important to computer science? Recursion is a type of method in computer science where a function is able to call itself to solve smaller instances of the same problem. The opposite style of code to recursion is the generic iteration style that we used throughout CSC108. Iteration is looping through a block of code until it solves the problem. So recursion is sort of like a type of iteration. There is technically no real need for recursion. Everything you do with recursion can be accomplished with iteration through loops. The real benefit to recursion however, is that it simplifies things when you must run through a lot of code and it cleans it up in an "elegant" way. This makes the program run faster and becomes more easier to look at and understand. For example in class, our professor was able to cleanly go through complicated lists with many brackets by using a recursion function. This saves a lot of time and makes "traversing" through complicated code a lot easier than iteration. 


In class, there have been several examples of recursion use in Python. We have not written any of our own recursion as of yet but merely trace the code in order to understand the core idea of recursion better. Most examples include complex, nested lists and ask for the result when a recursive function is run on them. The labs offered more practice with tracing recursive functions and although tedious, they offer practice which is valuable in understanding recursion. In general, I think the concept of recursion is very hard to grasp at first. I found the entire concept behind it to be quite foreign to me. You don't understand how it works by calling itself while you run it. This is why tracing the code is so important for practice and understanding. However,with practice, it becomes second nature to simplify your code and understand how each line is being run. Ultimately, that saves a lot of time down the road when you include complicated inputs. Learning recursion is absolutely vital I think so it is great that I took the time to learn it. It will help immensely in the present and future. 

Friday, 13 February 2015

Week 6: Trees, Branches, Forests, and Reading Week

It's the 6th week of CSC148 and that means it's the last week before reading week. This week's focal point was on trees. We learned some basic terminology and how trees worked within a program.

Not exactly like these trees per se.
The most important use of a tree is that it can be used to represent hierarchical relationships. This can be the structure in a program, relationships in an mathematical expression or directory structures. In programming, trees are an ADT (abstract data type) which consists of a root value and several subtrees linked by nodes.
A visualization of a tree used in programming.
Our professor did an interactive example during our Monday lecture. She made the student in the back row of the class stand up and he became the root of the tree. He would subsequently point to two other students in the next row to stand up and those students would point to two more students and so forth.

We studied this further in our labs where we would implement recursive functions when the input was a tree. Trees seem relatively simple to understand but the core concept behind recursive functions and how they work is a must. I struggled with recursion the past week but I was able to catch up and understand. Now, trees are a relatively simple concept to grasp.

Friday, 6 February 2015

Week 5: Introduction to Stacks and Queues

This week did not include a lot of lecture time. On Monday, a huge snowstorm snowed in many people and our professor was late as a result. Wednesday was the first term test so there were no lectures then. The term test was fair and it was easy to do well in if you studied for it.

On Monday, we looked briefly at unit tests and how they work as well as a breif description about stacks. There wasn't much detail since a lot of the lecture was missing as a result of the storm and with the term test coming up, most questions revolved around that.

In Friday's lab, the focus was on stacks and queues. It focused on practicing with stacks and queues and seeing how they work. We also focsued on the efficiency of queue implementation and how it would affect our code. This week was easier to understand in comparison to recursion but it was still valuable information to know about. Knowing how stacks and queues work make your program more manageable. Arrays and lists are random access and stacks and queues allow you to manage your data in a different manner.


Friday, 30 January 2015

Week 4: Brackets, Recursion and More Brackets

So starting this week, CSC148 mostly covered the topic of recursion. It sounds overly complicated and extremely confusing but it's not that hard to understand once given examples in class and tutorial. In essence, recursion in computer science consists of defining a function where it applies itself to the definition to solve smaller problems.

The whole idea is pretty foriegn to me since we never really talked about it in my high school CS class. So when my professor first began talking about it, I really had no idea what was going on. But she emphasized that using recursion is vital in programming. You never need recursion technically speaking but it cleans up your code and saves a ton of time.


The examples my professor used in class involved nested lists within lists. And of course going along with that meant brackets, brackets, and more brackets (even more than March Madness). She explained that nasty looking and complicated lists can be simplified and rather than taking using a loop to count the elements, simply use recursion. This began to make more sense to me. Who wants to trek through millions of brackets using a loop?

The other thing she emphasized was tracing the recursion within your code. This not only helps you find mistakes but also understand it better since everything becomes simplified when you are using recursion. This was also the focus of the lab in the tutorial this week which involved tracing functions with recursion.

This week's lectures and tutorials were particulary interesting in showing a method of creating functions that make quick work of complicated and nested inputs. Hard to grasp at first, recursion is actually relatively simple once you understand the core concept of what it does and it will make programming a lot easier.
Matrix