Friday, April 3, 2015

Week 12 - One Last Time

It truly is remarkable how we are almost done the course. All that's left is the final exam and the last assignment which is due today. Thankfully, my group and I managed to complete the assignment ahead of today meaning we can focus on any small changes we might need to make instead of stressing over completing it. 

Having finished the assignment as I said, it gives me time to sit down and write a post for the last time in this course. It feels like this course just started yesterday and now we're done with the lectures. As I've said time and time again, the course has been a very interesting one with some wonderful concepts relating to OOP (and some not so much). I felt the assignments and tests in this class were fair and a good reflection of what we've learned and what we were expected to know. The course was not easy by any means; it took a lot of time to sit down, review lecture notes, practice writing recursive functions, drawing pictures for linked lists and a whole lot more but at the end of the day, I can say that I enjoyed every second of it. The lectures were very helpful in learning the material for the first time, and the files professor Heap posted after lectures were very helpful in practicing the material. I also enjoyed the lab exercises because they required us to keep up with the material and in turn, not allowing us to fall behind on course work. I feel like the structure of the course is good and is beneficial to students. I'm hoping to do well on the final exam and achieve a good mark in the course.

In conclusion, I would like to thank the professors and TA's for their assistance and my friends for always helping me if I was ever stuck with something. 

Thank you!

Sunday, March 22, 2015

Week 11 - Revisiting Past Posts

In posts I made near the beginning of the year, I discussed how I was thoroughly enjoying this class and the material we were learning. Revisiting that now, I can say that I was right. Hoping to pursue a major in Computer Science, this class has really helped develop skills that will go a long way in helping me succeed. Coming into this class at the beginning of the semester, I had minimal knowledge of recursion, trees or linked lists. Now I can proudly say that I have learned all of these concepts and hope to expand my knowledge on them in the near future. My experience in this class has definitely been a positive one thanks to my wonderful classmates and of course, the great professors and TA's who worked endlessly to make this a successful course.

Throughout the semester I have been following along with posts from some of my fellow classmates. I found some of these points very interesting and also useful to acknowledge.

Anam Alvi:
I came across a post Anam made earlier in the year (Week 4) discussing her experience in the course at that time. She talked about how the course was her favorite one of the semester and how she really enjoys the concepts covered in the course. I can relate to that because as I mentioned above, my experiences in this class seem to be similar to hers and I don't find that surprising since she's going to be pursuing a Computer Science specialist which only means this course is an interest of hers.
The post can be found here: http://148slogs.blogspot.ca/2015/02/week-4-whos-your-daddy.html

All in all, Anam also offers some good insight on the topics covered in the course (along with very creative names for her posts) and sometimes reading other peoples course logs can be very helpful in a number of ways for example, understanding some material that was unclear or to relate to other peoples experiences.

Abhinav Chawla:
Abhinav also has nothing but positive things to say about this course which once again, I do not find surprising at all because it is a great course with a good structure and amazing professors / TA's.
However, instead of discussing his experiences in this class, I want to focus on one of his posts from earlier in the year (Why Geeks Should Write?) as I found this to be a very interesting and well thought out post. I liked the way he started his post with some background on what the word "geek" really means and how it came into existence. Without going into much detail about his post (link to the post can be found below), I would just like to briefly say that when I first read this post earlier in the year, I was inspired by some of the things he mentioned. One example of this would be how he discusses that instead of memorizing formulas, if we take the time to write down the concept and understand it, it goes a long way and that truly is something many people take for granted. Relating this to Computer Science, it makes sense that writing can truly come in handy. For example, when stuck on a problem, I like to sit down and maybe write some pseudocode or just the logic behind the problem and try to understand it. Therefore, I feel like this was a very well written post and I agree with the insight Abhinav had to offer on the topic at hand.
The post can be found here: http://abhinavchawlacsc148.blogspot.ca/2015/01/why-geeks-should-write.html

These are just a couple of the many wonderful course logs I have come across throughout the semester. Looking back at them now that we're coming to an end, I can say that it was a good learning experience. Reading over what other people have to say is wonderful as it helps the individual relate to others, learn from them and also assist them in any way they can. These course logs were a wonderful way to stay organized and also for students to seek others help when facing a challenging situation.

Tuesday, March 17, 2015

Week 10

Well now the test is over with and out of the way. Now we just have one assignment and the final exam left in the course. However, going back to the test, it was not very difficult and I had sufficient amount of time to complete it. The first question was very straightforward and I was able to complete that within 5 minutes. Part a) was simple once I realized the logic behind it and drew a picture which did not take much time and part b) required us to traverse through the tree given which I also found easy because I had reviewed all three traversal methods that we learned beforehand. However, the next two questions required me to think for a few minutes before I got anywhere. For the second question, it was very simple to a function we wrote in a previous lab exercise. I noticed the main difference was that this only returned even numbers which I quickly realized can be done with one simple if statement. The last question was about linked lists and this took me a while to complete. I first drew a picture like I had done for all the linked lists questions I've ever done. After drawing a picture and understanding the problem, I started to implement it making sure I keep track of everything I'm required too. The aid sheet I made for this test was very helpful because for one of the questions, it helped me solve a small mistake I encountered during the test. Now, all that's left is to see how I did and prepare for the next assignment and exam.

Sunday, March 8, 2015

Week 9

It feels like this course just started yesterday and now we're already finished two thirds of the course. The course has been a very interesting one and I'm learning a lot which is making this class very enjoyable. The second assignment was submitted recently and there were a bunch of remarks about the assignment. The assignment was an interesting one as it took a lot of time for my group and I to just sit down and think about the logic behind it.

The first part, implementing Tippy was not very difficult after we sat down and played the game ourselves a few times to understand how it works and the different winning possibilities. However, the strategy we were told to implement, Minimax took extremely long to understand. We were given a lot of help from the professors on the logic behind the strategy and that went a long way in helping us implement the strategy. It took a lot of time but even then, I think it was an interesting assignment that really tested our knowledge of recursion and helped us master it.

Furthermore, on another note, we learned linked lists this week and the reading posted on the class website was very helpful in understanding linked lists. Professor Heap emphasized that we should draw pictures to help us understand the problem and even though I'm not very fond of this method, turns out it was the most helpful thing I could have done. The lab exercise was also very helpful in further understanding linked lists. By drawing pictures, I was able to understand how to implement the functions required and finish the lab.

Sunday, March 1, 2015

Week 8

In the lectures last week, we mainly covered binary trees and binary search trees. We also went over how to traverse through trees by inorder, preorder and postorder traversals. Binary trees are something I looked over before coming to class so I did not think I would have much difficulty with it and the same goes for binary search trees as it is not very different from binary trees except for one or two conditions. However, at first glance, I got a little confused with a couple of the methods we completed but as we kept going, I started understanding everything and also being able to predict what the next step would be while writing recursive functions. I am hoping to be able to keep up with what we do and also be able to complete parts of the other functions myself without first seeing how professor Heap does it. It's crucial that I'm on top of all the work because of our test next week which hopefully won't be too difficult.

In the lab exercise for that week, we were supposed to implement recursive functions for binary trees and the lab took a while to complete, however it was a good learning experience as it was good practice for the upcoming test.

Friday, February 27, 2015

Week 7 - OOP

To begin, we must first understand what Object-oriented programming (OOP) really is. OOP is a programming language model which revolves around objects instead of actions. It also revolves around data instead of logic. OOP is based on the fact that we care about the objects we want to manipulate instead of the logic required to manipulate them.

Some of the basic concepts of OOP are classes, instance variables, inheritance, instance, method and object.

Class: A class is like a blueprint that helps to describe how to make something.
Instance Variables: An instance variable is a variable defined inside a method in a class and only belongs to the instance of the current class.
Inheritance: Inheritance is transfer of characteristics of one class (super-class) to another class (sub-class) which allows the subclass to use the methods from the super-class.
Instance: An instance is an object of a class.
Method: A method is a kind of function defined inside the class
Object: An object is a data structure defined by its class. The object comprises of class variables, instance variables and methods of the class.

Now that the basic terminology has been explained, it is time to actually go through an example of a class (docstrings have been omitted)


1. class Point:
2.  
3.     def __init__(self, coord):    
4.         self.coord = [float(x) for x in coord]
5.
6.     def distance_to_origin(self):
7.         return (sum([x**2 for x in self.coord]))**(1/2)
8.
9.     def __eq__(self, other):
10.        return (isinstance(other, Point) and self.coord == other.coord)



This is an example of a simple class called Point which takes in coordinates in any dimension and has a method that returns the distance to the origin of the coordinate given. 

Now we can go through each line of code explaining how OOP works.

Firstly, on line 1, the class is declared using the keyword class followed by the name Point and a colon.
Next, line 3 contains the special method called __init()__ which is a class initialization method that is called by Python when an instance of the class is created. This method is declared with two underscores before the name and two underscores after the parentheses. Inside the parentheses are the parameters however the difference in OOP is that you must have the first argument in every method called "self". On line 4, in the __init()__ method, a new instance variable is defined called coord which is preceded by the "self" keyword and then a period.
Line 6 is another method declaration, and line 7 returns the distance from the origin to the coordinates passed by the user.
Line 9 is an example of another special method in Python OOP which is also declared by two underscores before the name and two after the parentheses. This example is the eq method which checks if two instances are equal to one another. In this case, on line 10, this method checks if "other" which is a keyword to define the second instance is actually an instance of the class Point and if the coord's passed in are equal.

To declare the class shown above, you can do: 
point1 = Point([3.0, 4.0]).

This object creates an instance of class Point and now the methods in the class can be called using point1. One key thing to note is that in the declaration of __init()__ there are two parameters, "self" and "coord" however only one passed in the object we just created. This is because "self" is a special parameter which users don't need to include themselves.

Now from this object, we can access the other method in the class by doing point1.distance_to_origin() and this would return the float "5.0".

To find out how to use the final special method __eq__ we can create another object called: 
point2 = Point([3.0, 5.0]).

Now you can write "point1 == point2" in Pythons constructor and this would call the __eq__ method in the class. It would return False because even though point2 is an instance of class Point, the coord passed in is not the same.

Therefore, as shown above, these are the basic concepts in Python OOP and using the basic terminology and an example, I have shown how to write an example of a class, declare it and use it in Python.

Friday, February 20, 2015

Week 6

Some of the basic concepts relating to Object-Oriented Programming are classes, instance variables, inheritance, instance, method and object.

Class: A class is like a blueprint that helps to describe how to make something.
Instance Variables: An instance variable is a variable defined inside a method in a class and only belongs to the instance of the current class.
Inheritance: Inheritance is transfer of characteristics of one class (super-class) to another class (sub-class) which allows the subclass to use the methods from the super-class.
Instance: An instance is an object of a class.
Method: A method is a kind of function defined inside the class
Object: An object is a data structure defined by its class. The object comprises of class variables, instance variables and methods of the class.

This is just a brief explanation of terminology that can be very useful when learning about Object-Oriented Programming and without this knowledge, the rest can be quite difficult.