Sunday, 5 April 2015

The end of an interesting semester

This difficult semester has finally come to an end. The strike took a fair bit my patiences. With all the classes being cancelled and the lack of TAs, there was a lot of confusion about assignments and tests.

We got our tests back and I am very happy with my mark. I'm very excited for the exam because I really feel like I will do well. I want a Computer Science Major so I'm glad I got the marks that I got. I think this course was very important for my future in computer science. It taught me more about Python as a language, different methods and even different types of data structures.  I didn't have many hurdles in this course other than the strike. I had friends in upper years help me understand concepts and this made the course even easier.

My favourite concepts were recursion and tree traversals. Traversals were the most fun because solving what will be printed from a given tree is kind of like a puzzle and I love puzzles.

I think the best part about this course is the marking scheme. It is tailored to give each individual person the best mark possible. This is important for anyone looking to do a POST in computer science.

I also really loved Danny as my professor. He was very clear in his explanation of the concepts. I appreciated his willingness to be available through the hard times of the strike. He was also very wary of being fair to every individual who has taken the course in both this semester and last.

Overall, I am very happy with how things ended up this year. I am grateful for the opportunity to have been taught these concepts.

Thanks for a great semester!

Sunday, 29 March 2015

Looking back on recursion

Looking back on recursion, I'd say I still pretty much agree with what I had discussed previously. Something I didn't quite get the grasp of was the idea that every time you enter a new 'node', it is a new recursive call. For example, if you are trying to recursively go through a tree, every time you enter a new node, you temporarily leave the previous recursive call and enter a new one and rerun that function.
For example, if were to recursively go through this tree inorder, we start at 2. Inorder says we must look at the left subtree, the root and then itself. So starting at 2, we enter the left subtree which is 7. This just opened a new recursive call. We're not going to go back to 2. We're going to go to the left again. This 2 opens a new recursive  call and since 2 has no left, we return 2 and since it has no right children, we return to 7 and return that. Then we enter the right subtree and repeat the process.  In the end, the answer should be: 2, 7, 5, 6, 11,  2,  5, 4, 9.

I have commented on a few slogs for this particular topic:
  • http://csc148justinsong.blogspot.ca/2015/02/week-7-summary-of-recursion.html
  • http://nailedcsc148.blogspot.ca/2015/02/impressions-of-tracing-recursion.html
  • https://colslog.wordpress.com/2015/02/08/recursion/

These sloggers for the most part had the same ideas as I did when it came to recursion. In its most basic form, recursion is simply when a function calls itself within its own function but it is important to have a base case or we will have an infinity loop.

I also liked the way these sloggers approached problems. one went to another website for more information and others just worked with it over and over again until they understood.

I think what most people had issues with was the strike. It was really hard to get the help we really needed but I believe most of us pulled through.

Sunday, 22 March 2015

My impressions of week 9

We had a midterm this week and it was definitely a lot to handle with the strike. Studying for the midterm was all about drawing. I drew trees and tried different transversals and recursion methods. I also drew pictures for how to work out linked lists.

We learned how to delete nodes from a BST. This is a very tedious process because there are so many conditions one much consider. If you wish to delete a node, you have to be wary of what node will take its place. Since a BST has the condition where the left child is smaller and the right child is bigger, we would want to make sure that whatever we remove, the replacing node still fulfills the conditions that the left child is smaller and the right child is bigger.

Working on the lab was difficult. I didn't fully know how to work on the delete method but my problem was my understanding of delete. I kept forgetting that we have to be aware of what we are removing. We have to careful if we want to remove something in the middle because the whole tree could collapse. It's like a terrible game of Janga.

Other than these things, my week was really good. I'm really enjoying the course thus far and I am very glad I have taken this course.

Sunday, 15 March 2015

Linked Lists

This week, we learned about linked lists. This was a little hard for me to grasp. After class, I had to review it with a friend until I understood it. The part I had issues understanding was that every value has to be a node first. That is why we have to store it as an LLnode class. Then we have the wrapper class that can put them together.  Linked lists have a front, a back and a size. Each node in the list references another node. It's kind of like a line. The front points to another node, which points to a new node until a node points to the back.

When adding something to the back of the linked list, one must first make the value into a new LLnode. Then, it is important to change  the current back so it is pointing to this new node and then set this new node to back. I made the mistake of thinking that we first change the new back to he new node and then change the old back to point to this node. If it was done this way, we would have lost the reference to the old back. Then after all of this hard work, we have to add one to the size of the linked list.

Drawing pictures for these linked lists helped me very much. I was able to visualize exactly where things needed to go and how they should be coded.

Sunday, 8 March 2015

Binary Search Trees and Transversals

Binary search trees (BST) are just like normal trees but with a few distinctions. BSTs have an arity of 2. This means that a node can only have 2 children, a left child and a right child. The other distinction is that each left subtree is smaller than the root and the right subtree is bigger than the root. This makes searching for elements a lot more efficient because you don't have to transverse the whole tree. You can look for the certain elements based on the fact that the left child is smaller than the root and the the right child is bigger. There is a pattern in the height for these trees. To find the height, one can use log2n where n is the maximum number of nodes for each height. For example. if I had 15 nodes, then the height would be log215 and the answer is 4. Another important fact about binary search trees is that the data has to be comparable. This means that they have to be of the same type because you cannot compare an int to a str (Unless the str is an int in the str format, for which you can convert the str to an int). To help myself learn about these trees, I drew many trees and populated them with different integers to see how the trees would look

The next topic we learned about was transversals. There are different ways to traverse a tree: inorder, preorder and postorder. For example, inorder transverses a tree in the order: left, itself, right. So if we had a regular tree like this:
If we wanted to transverse this tree inorder, we'd start at the root but look at the left child, then this is a new recursive call, so we look at the left child of that child. So in this case, we return 9 because 9 has no left or right children and it is the last node(leaf) of the structure. Then we return to 5 and that is returned. Then we visit 7 and go to its left child. This goes on and on until the whole tree has been transversed. For this specific tree, we'd get:
9, 5, 1, 7, 2, 12, 8, 4, 3, 11

What I had the most trouble with was the fact that each time a new node is visited, it is a new recursive call. So if we start at 8, we check 5, it is a new recursive call so we check left again. This happens over and over until we reach a leaf or in the case of 4, we visit itself before we visit right. I had to draw many trees in order to figure out how to transverse a tree but now that I know, I think transversal is very fun.

Sunday, 1 March 2015

Abstract Data Types (ADT)

In this SLOG, I'll be talking about two structures. Trees and Stacks.

A tree (the data structure) looks like an upside down tree (the biological one). It starts off with the root and then it branches off. The last nodes that don't contain any other nodes are called leaves. There is only one way (path) to get to a specific node and paths cannot go in a circle. Also, two different nodes cannot have a path to the same node. This means that a node's children are exclusively its own children. These structures are levels of organization like XML and html. Recursive functions are also important in the case of trees because there are so many levels, it takes recursion to go through the organization. A tree can have lots of children but there is a catch. All trees have arity. This means the maximum number of children a node can have. This is important because if a tree doesn't have arity, the root would have all the children and it would just be a tree with a height of 2.

Stacks on the other hand are kind of like lists except you can only take off elements one at a time. If you imagine a stack of books, you know what the book at the top is but not the books underneath it. You can put a new book on top or even take the top one off but you can't put a book in the middle of the stack or take one from the middle because then the stack falls apart. The ADT Stack works in the same way. You can pop off the top element, you can push an element on to the top of the stack but you cannot take anything or put anything in the middle of the stack. The only way to see what is in the stack would be to keep popping off elements until the stack is empty. Stacks also have the method is_empty which returns a boolean to answer if the stack is empty or not. This helps when you pop off because while the stack is not empty, you keep popping elements. This is to make sure there is no error or infinity loop. You need to make sure that no more elements are being popped when the stack is empty.

Both of these structures are very helpful. We saw a similar structure to the stack in lab 4. We learned about enqueue and dequeue. They work in a similar way except we pop off the beginning of the list and push to the end. Like how any fast food order would take place. People who were there first would be served first and new people will be lined up in the back. This is different from stacks as people who were pushed lasted would be poped first.

I didn't have too much trouble with these ADTs. The lab really helped me understand them. They are valuable ways to store data. Which data type one picks really depends on how they want their data to be accessed.

Sunday, 15 February 2015

All about object oriented programming

The first few things we learned about object oriented programming( OOP) were the basics. We were taught that object oriented programming was about creating something (an object) that is created by a class. If we were to create the object elevator, we'd need to have methods that take the elevator up and one that takes the elevator down. We could also have a method to call for help if there was an emergency. These methods help create this elevator and make the elevator an actual, functioning elevator. We also had to create an  __init__ method for classes and this method helps to start up anything that we need prior to creating this object. For example, in the __init__ method for class elevator, we could create a list that would contain how many floors there are in the building. Then, the method for moving up can use this list to figure out if we even have to floor and if it does exist, take the person to that floor. The str and repr methods are pretty similar except the str method is a "prettier" version of the repr method. It needs to be as such because this is what is printed for the user to see and the repr is for the programmer. They are both representations of the class.

The labs themselves are really helpful because I get to play around with the topics we were introduced to. I always try out the labs before the actual lab starts. I haven't had any issues thus far because the topics are pretty self explanatory and if I do have an issue, just playing around in the labs helps answer my question.  

I really like learning by myself because I think I get the most learning experience when I learn from my mistakes so while learning about classes, I would keep making new classes and running them to see what values and inputs I get. In the end, it helped me figure out what I wasn't understanding or  missing so I could fix it.