Thursday, 2 April 2015

CSC148 Final Impression, omg!

      WAIT WHAT?!? We're done? Well that definitely flew by. I'd like to say that I very much enjoyed this course and the assignments were very fun. I especially enjoyed the game making assignment as it was very fun seeing your program actually do something interactive. Whereas in CSC108, we just had to implement methods and didn't really see how they all worked together. It was a very rewarding feeling after spending nights and nights trying to get the program working but once it did, it was such a priceless feeling.

     I was quite sad when labs were cancelled due to strike because that was one thing I was actually excited about. Going to labs to test if we understood what we learned in lectures. It was actually cool to have hands on experience in a lab ad collaborating with others in the section to prove some problems. Without labs, it was a struggle to understand a few concepts without TAs and working on them by yourself is not enjoyable either. I'm just glad that I got through them and the tests were very straight forward and as long as you've worked and tried the labs, you were good for them.

    I think the course itself has some interesting concepts that we learned this term such as recursion. As confusing as it is, it's quite cool to call its own function in its own method. Working with trees was also interesting. Most of the things that we learned really improves efficiency as seen in StrategyMinimax.

    I would say that it was a great term and thank you to all the TAs and Proffs that made this course a great one. Also a big shout out to the Profs, even though some labs and TA support were wiped out for us, you still tried to make the impact of the strike as little as possible. We still covered majority of the content and we had a small impact on our course marking scheme. I really enjoy computer science for someone who had no prior knowledge coming in and I enjoy all of the logical thinking, problem solving and the trial and errors that it entails and I plan on continuing as a major with another major in who knows what...... :) Anyways, happy programming and it was a good semester! Cheers Geeks! :) Keep SLOG-ing. It's important (refer to week 1 post) :P

Friday, 27 March 2015

Week 11



     Reading my previous posts, I have seen that I had great trouble with Recursion. Now that I have done many exercises dealing with recursion, I feel pretty comfortable with them as we have done so many functions in Assignments 2 and 3 that it's coming naturally when you're trying to implement a recursion method.

Also, Linked Lists now aren't so bad. I think the trick is to continue doing exercises until you get the hang of it and start gaining comfortability dealing with these sets of problems. Anyway that's all I could really write about this week and everything else has been going pretty well.

Other news, the STRIKE IS FINALLY OVER. I don't know how the strike ending the week before school's done is going to affect our marking scheme but I feel like all of my courses have been on a rocking boat and swaying in so many directions that I don't even know what will happen. Im just hoping for the best because I really want to get the most out of my tuition fee and I feel like I did not get that this year. But hey! Welcome back TAs, I have missed you! I have now come to realize how much Computer Science courses rely on labs and tutorials to understanding and apply the concepts we've learned. I hope this doesn't happen again in the near future. It's really a struggle.

Thursday, 19 March 2015

Test Numero Dos

      Week 9 has been a hectic week due to having a test in both CSC165 and CSC148 and the lack of TA support. Regarding the strike, I wish it was over since most of my knowledge of concepts and problem solving are cleared up during Tutorials and Lab Exercises. So, going to the two tests were filled with uncertainty with a lack of confidence of knowing these concepts. A lot more work had to be put into studying as self teaching was the key to get by this week and tests which greatly put me behind in other courses but hey! You have to do what you have to do and balance all of your courses.

Anyway, the test was not too bad. It was pretty straight forward and it's everything that we've seen before in class for sure. I noticed that I had made a mistake in the first question when they ask what is the biggest height a binary search tree could have with 20 nodes. To my understanding, I thought that each node had an arity of 2 which made me think that it had to either have no children or 2 children so I did not think of the possibility of the tree to be just one long path of 20 nodes. But now I am aware of my mistake and this possibility.

The recursion part was alright, It was to only list the even nodes in the tree from a certain interval if I remember correctly. So if the node was in the interval, you'd have to check the left tree and right tree and so on and create an if statement that only returns that node if " n % 2 == 0".

The linked list part of this test was some what challenging. But the handy dandy cheat sheet really came clutch (Urban Dictionary: the crucial moment that comes between winning and losing)! But obviously I was winning (maybe not, we'll see) because the code was pretty similar to the lab07 exercise when "delete_after" had to be implemented, if I'm not mistaken. You just had to manipulate the code a bit to get it to check the right conditions and to add the value of the next node to the current one then skip it. Just some minor changes to that code and bam you got it. If it isn't right...... well then.... part marks, am I right? Hahaha.

Overall, not such a bad test, we'll see about that though. Anyway, the last few weeks and the final push with no TA support to get through this semester and I am...... feeling...... indifferent about it. Like I want to finish the semester already and we're so close to the finish line but with no TA support, I don't know if i'll make it there, especially with no TA help with A3 and as the exam approaches to clear any misunderstandings and concept confusion with labs. But we got this! Work hard, Program Hard! :)

Saturday, 14 March 2015

Linked Lists

     Hello there once again Sloggers! Can't believe we're already more than half way done this Winter semester, let alone 1st year! Almost there guys, the final push!

       So Week 9 talks about Linked Lists! To be honest, this concept was some what confusing to me at first and watching this video really helped me grasp the concept.

So basically the most typical structure of Linked Lists code goes somewhat like:

cur_node = self.front  #This is to set a variable to the first node in the list        while <some condition here>: #Depends on the problem

   cur_node = cur_node.nxt #Update the node to the next one

I think of it as a normal list but instead of looping through a list automatically, you have to keep updating the node that you want to check and if it satisfies the condition given. Also, you have to take into consideration when the list is empty, or when the you reach the end of the list or if the next node is None, or if it's size is 0, and make "if statements" that satisfy those conditons based on your method accordingly. 

We had a lab to do for this concept but unfortunately, without TAs was proven to be very difficult because we didn't have the extra guide to lead us to the right direction especially that it is a new concept. But overall, the lab was not too bad but I still need to practice cases where if the loop reaches the end or if there aren't anything in the list because I tend to miss some important things in my code that will make it run incorrectly. More practice needs to be done with these methods but other than that, not too bad to get my mind around. 

Sunday, 8 March 2015

Week 8 - Trees and Binary Trees

This week we've been taught how to create trees and binary trees. Trees look something like this:
Trees are a set of nodes with directed edges between pairs of nodes. An edge connects a parent node to a child node. The node at the very top is called the Root Node which is the one node that does not have a parent in the tree. The parent node is a node that contains children. Also the length of the path is the number of edges in the path of the tree. 

These are some more useful terminology that is helpful for the structure of trees:
  • A leaf is a node with no children (such as #1, 4, 7, 10 in the diagram)
  • Internal node is a node with one or more children (#5, 3, 8 in the diagram)
  • Subtree is a tree formed by any node and its descendants and the edges connecting them 
  • Height of the tree is the maximum path length + 1 
  • Depth is the height of the whole tree minus the height of the tree rooted at that node
  • Arity or branching factor is the maximum number of children for any node
We were also introduced to a specific kind of tree which is called the Binary Tree which looks like:

Distinctive factors that make the binary tree special is that..
  • Binary Trees is a tree with branching factor of 2. Which means that each node has a maximum number of 2 children. 
  • The children in a binary tree are called left and right child 
  • Binary Search Trees have a specific property which is that for evener node, its value is greater than all values in its left subtree and less than all values in its right subtree. 
    • It's good to note that each subtree as well is a BST.
    • For example, in the diagram above, all of the nodes on the left child side of 68 will always be less than the nodes values on the right child side of 68 and the pattern still continues as you keep going down the subtree. For example, look at the bottom of the subtree of the node 11. -22 is less than 2 which means the left side is always less than the right side.
Through out the labs, we have worked on some recursive methods that calls on trees that gets a better idea of how they work. Here's an example: 

(Will insert pictures later when I get on my CDF account)

You can note that the base case is mostly when there is no children (if self.left == None and self.right == None) which always occurs at the very bottom of the tree. 

I think I still need to review this concept as its difficult to wrap my head around but doing the labs really do help practising the concept lectured in class. I really hope the TA strike comes to an end soon as it's my main source of understanding computer science concepts better and its where everything starts to make sense with my TAs help even for CSC165... but other than that, ill try my best to understand it on my own and will try my best on the next test...............ha ha... anyway Happy Slogging and good luck on Test 2 everyone! :) 

Saturday, 28 February 2015

Week 7 - Object Oriented Programming

For this week, i'd like to indicate that i'd want my Object Oriented Programming SLOG that i've previously written to be marked which is linked here.

In addition to that post, i'd like to add more details and go into depth into the concept of OOP. I've gotten positive feedback that my post was very informative and useful but i'd like to demonstrate these definitions into examples that we have come across throughout the course to get an idea of what it's really talking about and to help those who learn through examples instead of merely memorizing the definition, I know I do.

I will show all of these examples based off of our assignment with Subtract Square, as you all know was our Assignment 1 which was a very good exercise to practice these new concepts in OOP.

So firstly, in Subtract Square, we have encountered many Classes which is defined in my previous post.

Examples of Classes in our assignment are shown in the General Classes that we had to make for the game followed by its docstring that informs us what types, methods..etc are in this particular class, such as:
                 class GameView:
            '''
                             A game view for a two-player, sequential move, zero-      
            sum, perfect-information game.
            '''

       class Strategy:
            '''Interface to suggest moves for a GameState.

            Must be subclassed to a concrete strategy.  Our    
            intention is to provide a uniform interface for  
            functions that suggest moves.
            '''

       class GameState:
            '''(Insert docstring of all the methods in this class...
            you get the idea)
            '''
As stated in the previous post, these classes contain methods and also __init__, __str___, __repr__ etc and whatever relevant methods the programmer wishes to include into this class.

The second thing we've encountered in Subtract Square that is an OOP is Inheritance (Refer to previous post for the definition).  We encountered this in Subtract Square when we were writing specific methods of Subtract Square in its individual Subclass. 

Here's an example of how Inheritance and Subclasses came into play in our assignment:

We had to make a subclass for the general class because the general class is vague enough that we have to refer to a subclass for specific games, situations, etc. Like our assignment, we made a general class of any particular Game, but what if we wanted to play a specific game? We use Subclasses because every game has different rules and in these subclasses we can use inheritance or override these methods to correspond to the specific game we wanted to play, in this case Subtract Square:

from game_state import GameState
from subtract_square_move import SubstractSquareMove
from math import sqrt
from random import Randint 
#This is a crucial step, not importing causes Errors and will not be 
#able to inherit from your general class if you did not import it

class SubstractSquareState(GameState):
#General structure of subclass referred to previous post
#"class SubclassName(ClassName):" 
     '''The state of a Subtract Square game

     current_total: int    --- total to be subtracted from
     '''

So above shows an example of how we created a Subclass in our Assignment Subtract Square. Next is how does this Subclass use Inheritance. Inheritance can be represented in the __init__ method such as so:

def __init__(self, p, interactive=False, current_total=0):
     '''(SubstractSquareState, int, str) -> NoneType
      
     (insert docstring here)
     '''

     GameState.__init__(self, p)
     #Notice that I cut out most of the code in __init__
     #I just wanted to emphasize the Inheritance part of this code

So the code above that is in the Subclass SubtractSquareState shows inheritance in its __init__method. In this example, it is inheriting GameState and also adding another argument 'p'. This causes the Subclass to inherit everything the general class has but also adding any argument the programmer feels is appropriate for this specific game that is not in the general class because it is not general enough for each game to use. 


I hope these examples are relatable and explain these major concepts of OOP that we've come across in this class. If you have any further suggestions, commentary, or opinions, feel free to comment. Also refer back to my post which is linked at the beginning of this post to get the general idea and definitions of these concepts. Happy Programming Sloggers! 


Thursday, 12 February 2015

OOP, there it is! OOP, there it is!

(Haha, clever name I know, trying to make SLOGs a little more interesting... failed. Anyway, if you didn't get it.. forget it.)
Disclaimer: I'm lame, I know.

     Anyway, on to the topic. This week we're summarizing what we know about Object-Oriented Programming (OOP) concepts. First of all, OOP is a programming language model organized around objects rather than "actions" and data rather than logic. (Definition from here). For those who want to clarify what it is.  Basically, the difference is that in logic, it takes an input, processes it and produces an output of data. The material we've mostly covered so far in CSC148 is all about OOP. Where we take objects and we want to manipulate them rather than the logic manipulating them. The object represents the state and behaviour.
 

       So far under the OOP umbrella that we have learned, we learned the concepts of defining classes and subclasses, using inheritance...etc which are the basic concepts before you write any code. The key concepts that we covered thus far are:

  • Class: which is an object that defines a set of attributes that characterize any object of the class
    • Class statement is written as:
              class ClassName:
                  """Class docstring
                  """
                  #followed by methods your class wants to cover as well as __init__, __str__, __repr__... etc 

    • We also had some practice in creating instance objects, and accessing attributes in classes  
  • Inheritance: allows us to add extensions of existing classes to a new class which is the Subclass
    • The subclass is the child class where as the existing class (as described above) is the parent class
    • This is useful when you want to make a general class and apply it to different circumstances of that class. For example, if you want to make a general class Shape and make subclasses of specific shapes such as Square, Rectangle ..etc. This could be done by using inheritance and/or over-riding methods in the class itself. 
    • Inheritance in subclasses look like this:
                                SubclassName(ClassName):
              """ Subclass doctstring, don't forget to mention that            
              it is inherited"""

             def __init__(self, attribute, attribute):
                     """
                     """
                   ClassName.__init__(self, attribute, attribute)
                   #and assign anything else you need in this    
                   subclass that is not in the superclass

I think these are the two main concepts of Object Oriented Programming that we have covered so far. We've worked with a lot of problem solving involving these concepts and had thorough practice in them. Also, I think going over the assignment and doing all the labs were a great practice in understanding these concepts! Also, this website has helped clarify any confusion I had with OOP and also looking back at the Proff's slides and hope this will help you as well. (Link here!) Cheers!

Edit: Here is a continuation of this post if you want to see these concepts come into play in problems that we've encountered in class to get a better grasp of these definitions and ideas. (Link to Examples Here!)

Saturday, 7 February 2015

Recursion, smurshion..

     Ahhhh Recursion, the most interesting thing i've come across in 148 thus far. Looking at it for the first time was clearly A LOT of confusion. Thoughts of "Why is it calling itself in it's own body, what does it even do, can it even do that?" and being confused for about a week until I woke up one morning, and i'm not kidding you when I say I had an epiphany after I dreamt about trying to solve a recursion problem in my sleep. Haha I'm laughing as I type this because this seriously sounds insane, even to me. No joke, I can kind of explain this phenomena by something I learned while studying for my Psychology midterm on Tuesday. It's called Problem-solving theory where someone solves the problems that they encounter when they're awake in their sleep and dreams.
    Anyway, that's a fun story for a SLOG but anyway recursion is a concept where it involves breaking down bigger problems to smaller problems and smaller problems until it can be solved trivially. After thinking about it for a while on my train ride to my 11AM 148 lab after my 'dream', I was envisioning how Python reads this code and what i've come up with is that it checks the input that you give it and sees if its the type of object that "isinstance" wants it to be (well in the case of the recursion problems that we've worked on in the lab). If it is not the specified object type that "isinstance" wants and is checking for, it goes to the else statement and returns whatever it wants it states to return. But if it is, it goes to a return statement that involves a list comprehension where it loops over that list and calls the method again until each nested list is computed and until it can be solved trivially which is pretty neat. Well this is my understanding of how to trace the code.
    Tracing a bunch during the lab was really really helpful in understanding how Python goes through a nested list using recursion but practicing it over and over and tracing it, you really get the hang of it. I'm sure I need more practice in understanding how it loops over as I probably messed up my test because I got confused at one point but hey, i'll learn from my mistake. I also need to practice more because i'm sure we're going to have to write a bunch of them soon and it's a bittersweet feeling. Bitter because i'm sure it'll be tough in the beginning but sweet because who doesn't love problem solving questions and it's very useful especially for calculating something in nested lists and other things! Yay, more programming fun.


P.S. Recursion is pretty difficult to understand but when I was stuck, I stumbled upon this website (here) and really helped me understand the concept a little more. Hope this helps you as well! Cheers xoxo.

Wednesday, 28 January 2015

Week 4: First Impression! Eek!

Hi again Sloggers!

       CSC148 has gotten through a few new topics these past few weeks and all the material so far that we have covered have been interesting. We discussed how to construct classes such as how we did in CSC108 and were taught the efficient ways of doing so which were pretty straight forward. We also learned a new concept called "list comprehension" which is neat and I wish I had known about in CSC108 because it would save me a few lines of code which looks neater and saves time. I'll be definitely using this a lot in the future. 
      These past few weeks have been at a quick pace in which we are expected to know a lot about python and it is our job to apply this knowledge to problem sets. We have done Stacks, Inheritance and Subclasses which are all new material and are quite neat because I did not know that you can create Subclasses with classes that we've already made. It's very useful for when you want to make a general class that applies to a bunch of specific problems such as the example in class where you can make a general class "Shape" and make it's subclasses the different kinds of shape such as "Triangle", "Square", "Circle" since every shape has different characteristics...etc. In order to do so, we must remember to use inheritance or override the methods in order to use it for a specific subclass. 
         We used the knowledge from lecture about Subclasses and Inheritance and applied it Assignment One where we have to create and develop a game called Subtract Square. This assignment was pretty overwhelming at first due to the fact that we were so used to CSC108 assignments where we were given the format of the whole method but the function body and all we had to do was fill it in. This assignment was challenging because we had to figure out what we had to do and come up with a variety of ideas on how to implement these ideas as we are given the task to develop everything from scratch. I like to refer to it as "taking the training wheels off that big kid bike" because that's really how it felt like. But as weeks went by and the more we read the assignment hand out, the clearer it became. The task we had to do and was pretty neat to see the outcome that we've actually designed and implemented a functioning game from scratch.
       Labs were also cool to experience as it is our first time in a computer lab and actually working on Computer Science exercises with peers. It gives you the opportunity to collaborate with others in lecture which is a really good idea to test out your team work and problem solving skills. I believe this really helped with completing the assignment as well! Furthermore, CSC148 has been on a quick start and has been a bit challenging to grasp the new concepts of problem solving and applying our coding skills but i'm really up for the challenge this semester! So here's to a great semester with all you geeks! :) Cheers.


I would also like to comment on the achievements we've had so far and how our programming skills have progressed. This feeling is very well explained in this SLOG post (This SLOG), I too played the game many times because it's something that my partners and I have created and not for the sole purpose of its entertainment. Even though this game is very simple, the work and effort you know you went through to achieve this result is something very accomplishing and something that makes me proud to be studying what i'm studying. 

Saturday, 17 January 2015

Why Do Geeks Need to Write?

          In order for the world to expand it's knowledge with innovative ideas from outstanding individuals, one must learn and have the key skill of communication to communicate one's ideas with the world. There are many forms of communication and writing is a very important one! I guess you're wondering, 'Who may these outstanding individuals be?' Even if you aren't, well the answer is anyone, geeks included. Our mind is constantly producing such exceptional and phenomenal ideas that the world is just waiting to hear. In order for people to share their ideas they must communicate their ideas in a way that is accessible and easy for everyone to reach, which is why writing is such an important skill for geeks (or anyone)!
     
    Let's take Sir Isaac Newton for example...
         This handsome fellow was filled with such brilliant and extraordinary ideas and concepts that helped shape science as a whole. All of his work and his theories were published in the famous PhilosophiƦ Naturalis Principia Mathematica, which he published himself. But where would science be if he had not published his work and ideas in writing? Will one simply just keep communicating one's ideas to another until the word gets around? But let's take the game "Broken Telephone", as a message gets passed on to another and gets to the very last person in the chain, the message that has been passed on has been changed with a different meaning that it once had originally from the beginning. A good way of avoiding this is to keep it in writing, in black and white proof, so that nothing can be disoriented. Also, if he had not published his writing and ideas in text, other geeks that came after him would not be able to expand or correct his ideas in more scientific accuracy. This could result in scientist stating the same theory over and over without knowing that it already exists when the theory could already have been expanded on. This also allows scientists to work together to make the process easier and more efficient by working as a community.
       I know this example is science/physics based but this applies for all geeks in any field including Computer Science. Communicating in a text based interaction is a very important skill for geeks to do to expand technology and to expand the worlds knowledge. It is also beneficial to learn and explain mistakes you've made and have learned from. Another excellent example is Piazza. If one has any questions or important statements that they may think may be important and beneficial for other classmates to know, their ideas and questions will get around a lot quicker resulting us to all work as a community for each others successes. Taking the Piazza concept and putting it into blog form... you get SLOGS, which is this very post right now (my very first one to say the least). The main thing that i'm trying to get at is: Writing is an important skill that geeks need to know and must learn in order to present and share their ideas to the world to expand the world's knowledge as a community for everyone's benefit.