Wednesday, 22 April 2015

Week 3: Why Geeks Should Write

        Writing is a fundamental skill that is required not only in academia, but also in everyday life. For instance, Life Science students have to write lab reports, English students have to write essays, and even computer science students have to write comments in their programs. Hence, writing is a universal skill that is essential in any subject field. Particularly, in the field of computer science, the benefits of writing include honing our communication skills, helping to keep track of all the important details, and challenging our creativity.

To begin, have you ever been in a situation where you try to explain some scientific concept to your friend, but failed to pass on the idea even though you clearly understood the topic? Well, it means that you did not fully grasp the concept yet. This is because if you actually master the topic, you could have explained it in a way so that your friend would understand. When we write about a scientific topic or even our daily routine, our mind works strenuously in order to express our thoughts in a way for readers to understand. This process requires the writer to constantly rethink about the concept that is to be written, and forces him/her to express ideas in a coherent manner. The writer only finishes the writing when he/she has fully explained and mastered the concept themselves. Hence, writing perfects our communication skills by practicing our abilities to express ideas clearly and explain concepts in a logical way. Also, writing clarifies our thinking by forcing us to solidify our thoughts and knowledge and put them in a cogent order. In the study of computer science, the ability to express ideas are involved in writing comments in programs. This is because programming usually involve a team of programmers who each write code for different parts of the program; therefore, comments are necessary in order for colleagues to understand their partners’ codes. Furthermore, writing practices our ability to think logically, which enhances a programmer’s skill to program in a logical manner.

Secondly, according to Steve Rydz's (http://steverydz.com/2013/11/19/keeping-a-debugging-journal/) and Tinypig’s  (http://tinypig2.blogspot.ca/2011/06/keep-debug-journal.html) slogs, keeping a debugging journal is extremely helpful. By recording problems and hurdles encountered during programming and their respective solutions, the programmer can see his/her own blindspots and identify troubling areas that call for improvement. Furthermore, if in the future a similar problem is encountered, the programmer can quickly remember its solution by reading previous journal entries. Or even better, the programmer can quickly come up with a solution right on the spot, because he/she understood the problem from writing down the solutions before. Thus, writing a debugging journal helps the programmer to better understand his/her own weakness, and reinforces the programmer’s understanding.

Finally, programmers don’t have to write about academic articles, rather, they can write about anything. Even if the writing is about the writer’s complaints and daily routines, or even a random anecdote or short stories created by the writer. This is because writing itself forces the writer to constantly come up with new and creative ideas. By simply just writing about anything, a programmer can enhance his/her ability to be innovative and creative. Furthermore, innovation is a vital part of programming since algorithms require creative solutions. Thus, in conclusion, programmers should view writing as a daily homework, and spend at least ten minutes everyday just to write.  



Wednesday, 1 April 2015

Week 12: Reminiscence and last week of class!

        In the last week of class, my emotions were a mixture of euphoria and nervousness. I am elated that summer break is approaching, however I am also nervous about the upcoming exams. Here is a summary of what was taught each week:


Week 1: Review of CSC108 where the  implementation of class was learned. Init, and eq methods were reviewed.

Week 2: Continue to review CSC108 regarding the implementation for rep and str methods. The property mechanism was taught along with introduction to abstract data types such as stack and queue.

Week 3: Introduction to exception and tracing recursions

Week 4: More tracing of recursions

Week 5: More on recursion along with the review of writing unittest.

Week 6: Structure and implementation of a tree involving usage of recursions (count_leaf, count_node, etc.)

Week 7: Binary search tree and three methods of tree traversal (inorder, postorder and preorder).

Week 8: Class LinkedList and LLNode. Recursion was practiced through writing methods for LinkedList (append, prepend, delete).

Week 9: More implementation of binary search tree and recursion.

Week 10: Discussion on assignment 2’s strategy minimax. The professor also taught ways of choosing test cases for an unittest.

Week 11: Types of sort such as quick sort, merge sort and etc. Also definition of big-O and time complexity such as lg(n) are taught.

Week 12: Leaning more about big-O


Looking back over the course, I realized that more than half of the materials learned in class involved implementing recursion. Hence, I should focus more on practicing recursions in order to prepare for the exam. Furthermore, throughout the term, although I have encountered many conceptual hurdles, I solved them nonetheless. Some major conceptual hurdles include understanding recursion and linked lists, where both problems were already discussed and resolved in my slogs. Lastly, strategy minimax in assignment 2 was the most difficult part in all three assignments. What made writing assignment 2 much harder was that help centres are unavailable due to the strike. Hence, I am really glad that strike is over. 

In conclusion, although I used to dislike writing slogs, I now find it really helpful. I would definitely recommend later years to write weekly slogs  since writing improves the understanding of complicated concepts.And lastly, I wish everyone good luck on their respective exams!

Thursday, 26 March 2015

Week 11: Everyone had a mental breakdown. I am not the only one.

        After revisiting my week 8 slog, I felt ashamed to have blamed my inability to do assignment 2 on the professors. As a recap, in week 8, my group and I had trouble writing strategy minimax. And when we went to office hours, the professors told us to figure things out on our own. Out of frustration, I complained about the incident in my slog and declared office hours to be useless. Now that I look back, I had to disagree with my previous opinion. As a matter of fact, Danny and Diane did provide some hints regarding minimax, however, they couldn’t tell us the exact way to tackle the problem since that will be telling us the answer. Moreover, they even sent an email to the students describing the approach to the problem. Furthermore, minimax wasn’t as hard as I though it would be since my group managed to finish it in week 9. Although our approach to minimax differed completely from the standard answer, it ran perfectly nonetheless. Out of self interest, I also read over my other older slogs and discovered that I still agreed with the majority things I once wrote. For instance, in Week 4, I mentioned the CSC148 is significantly harder than CSC108, and that I was not used to this fast paced learning environment. Well, I still feel the same, especially when the strike is still continuing and no help centres are available for me to ask questions. Just when I got used to my new schedules and courses, the strike happened and messed up my pace. I now lose the opportunity to get extra help, and have to spend longer time struggling to understand new course materials on my own. Similar to my first three weeks, everything was a struggle as I tried to get used to another new environment. However, I also felt relieved to have solved many complicated topics in my slog. Each time I had some problem regarding recursion (in week 5), OOP (week 6), or inked lists (week 10), I always try to figure things out on my own. After I have fully mastered these concepts, I write them in my slog and explain them in a way that can help other readers’ of my slog master the material. Now that exams are imminent (a month go by really fast!), I realized that studying for CSC148 is so much easier since I already understood all the concepts taught in class. Hence, slog is useful for learning purposes since it reaffirms my comprehension after I tried to explain them in words. 

         Out of interest, I read over some other people’s slogs and discovered that they also had difficulties with assignment 2. For instance http://egq148.blogspot.ca/ mentioned in “The Seven Week Itch” that he/she also had some problems with minimax. Interestingly, one thing mentioned by the blogger caught my attention since it coincided with my previous thoughts: “How are we supposed to write a program that can never lose, if we ourselves are always capable of losing?” I remembered when I had problems with A2, I also felt like minimax is an impossible task. Furthermore, I also read Jingyu’s slog and discovered that we had the same problem regarding the method delete in linked list. (I mentioned that I had trouble understanding linked list in week 10. Similarly, Jingyu also expressed her frustration with delete in her week 10 slog). The difference between us is that I figured out how delete works on my own, whereas Jingyu didn’t. Hence I messaged Jingyu offering her my slog. Hopefully it will be helpful. 

        In conclusion, I want to thank Huan Ling, Jingyu and some other people for mentioning me in their slogs. At first, I disliked writing slogs and considered them to be a waste of time. However, slog is a great tool for learning since it helped me clear out my own misunderstanding regarding certain concepts. Furthermore, I felt accomplished that other readers also found my writing to be useful and helpful. Lastly, I want to mention Christian’s slog. His slog has helped me understand various complicated concepts. And one thing that I really liked about his slog is that he would relate the class materials to some other applications such as math. For instance, in week 7, he related recursion to the Fibonacci sequence. Because I am also in the math major, seeing a topic that is of my interest really helped my understanding. Moreover, his slogs are visually appealing and I liked his choice of pictures. Here is a screenshot of his beautifully done slog:





Saturday, 21 March 2015

Week 10: My impressions of week 9

         Like Week 8, Week 9 was also a busy week since I had multiple assignments and tests, including the second term test for CSC148. I mentioned in last week’s slog that I didn’t thoroughly study linked list, and that I hope nothing related to deleting nodes will be on the test. Unfortunately, according to Murphy’s Law, “anything that can go wrong, will go wrong.” On the third and last question of the term test, I had to incorporate the idea of deleting nodes. After the test, I discussed my answers with fellow classmates and not surprisingly, my answer for question 3 was wrong. The good thing was my answers for question 1 and 2 were correct. So hopefully, part marks can be given on my attempt at question 3.

        Because of my lack of understanding regarding linked lists, I decided to re-learn the class materials. With the help of my friend a person's slog, I finally learned the structure and implementation of linked list. One important tool that my friend taught me in order to understand linked list is to draw pictures. To begin, linked lists are lists made up of connecting nodes. It is shaped like a chain where each node is connect to only one node. In technical terms, linked list represents a sequence of a collection of objects (nodes) with a value and a reference to other similar objects. To understand its structure better, drawing pictures are really helpful. Here is a pictorial representation of linked list: 

To be more specific, linked list consists of two classes. The first one is called LLNode and it represents one single item (node) in the linked list. This object stores the value of a particular node, and the value of the next node connected to that particular node (represented by the ‘next’ attribute in the init method). The diagram above refers to three distinct nodes connected in the form of a linked list. The first node has the value 1, and its ‘next’ attribute refers to the second node with the value 2. The second class is called LinkedList, which represents the entire list with nodes connected in a particular order. It contains three main attributes, the first being the value of the frontmost node (stored by the variable ‘front’), the second being the value of the last node of the list (stored by the variable ‘back’), and the last being the number of nodes in the linked list (stored by the variable ‘size’). In the above diagram, ‘front’ refers to 1, and ‘back’ refers to the value 3, whereas size refers to 3 since there are three nodes in total. Furthermore, many other methods such as append, delete_front, prepend and __contains__ are also implemented in the class LinkedList. 

        The part that I had the most trouble with was deleting a node. Now that I learned to draw helpful diagrams, the concept of deletion doesn’t seem as hard. To delete a node with a designated value after its first occurrence involves assigning a variable called cur_node (current node), which keeps track of the value of the current node. Here is what the code looks like:


Basically, the code means if the first node exists and has a value, make the variable cur_node refer to that first node, represented by lnk.front. Then continue to traverse down the list looking for the node with the selected value. In case the entire list does not contain the value we are looking for, we have to accompany the while loop with the condition that cur_node always has to exist (not None). Furthermore, if we did not find the node with the value we are looking and the list still has unvisited nodes, assign cur_node to the next, upcoming node. Now, the while loop either terminates if we already searched through the entire list or if we found the node with the value we are looking. If after traversing the entire list, no node contains the value, the if statement determines what to do. If cur_node refers to the value None, it means that the entire linked list does not contain the value we are searching for, hence nothing happens. However, if cur_node exists, we either delete the node after it (if cur_node is not the last node of the linked list), or we do nothing since cur_node is already the last node of the list (the ‘back’ of the list). Here is a diagram:


If the value we are searching for is 55, cur_node will at first refer to 17. Since 17 does not equal to the value we are looking for and cur_node is not None, cur_node is now assigned to be the next node with the value 23. Just like 17, 23 also does not equal to 55, hence cur_node now refers to 55. Since cur_node == 55 == value, the while loop terminates. According to the if statement, cur_node and cur_node.nxt both exists. Hence, the body of the if statement is being executed. Since lnk.back is not cur_node.nxt (meaning node 72 is not the last node of the list), cur_node.nxt will be equal to cur_node.nxt.nxt. This means in the node with the value 55, its attribute ‘next’ will now refer to the node with the value of 14 instead of 72, hence deleting the node with the value 72. Moreover, the size will be decrease by the value 1. Now, if 14 is the value we are looking for, cur_node will end up referring to node with value 14. Since 14 is the last node of the list, cur_node.nxt is None, and nothing happens because the if statement never gets executed. Let’s say the value we are looking for is 25, which is not in the list. In the end after traversing through the entire linked list, cur_node will refer to None, since cur_node = 14 and cur_node.nxt will be None. Similar to the previous example, nothing will happen.

        In conclusion, drawing pictures are sometimes critical for understanding complex data structures. Despite the fact that I was occupied with tons of work last week, I am really satisfied with myself and my problem solving attitude.  In the end, I want to thank the person who wrote the slog http://egq148.blogspot.ca/ since it helped me understand linked list and how it works. 

Thursday, 12 March 2015

Week 9: My impressions of week 8

        Week 8 was both a happy and sad time for me due to three major incidents. The happy event was that my group and I successfully completed the code for strategy minimax two days before the deadline. And the sad parts of the week was that I handed in the wrong file during submission, and that I failed to fully prepare for a test.

        Now, I will begin with the happy part of my recount from last week. As a recap, during week 7, my group had trouble implementing strategy minimax. Fortunately, after discussing and thinking for multiple days, we were able to come up with a solution. During multiple group meetings, my group and I knew we had to use -1 as a multiplier to change the score after the player switch turns. However, we were unable to multiply the multiplier into the score list because it contains many lists of inner lists. After thinking about the solution for days, my partner had an interesting idea of using both the max and min function to calculate the score. We then created two functions, where one was called max and the other was called min. And we used the min function within the max function, and similarly, the max function within the min function. In this way, during a game between the player and the computer, the max would return the score of 1 when the computer is the next player, while the min would return the score of -1 to the computer when the opponent is the next player. The min function served a similar purpose as multiplying the opponent’s score by -1 in order to obtain the computer’s score. Proud of our creativity, we successfully completed the code and showed it to Danny and Diane, to which they both replied the word “interesting.” Although our code might deviate from the standard answer that the professors’ expect, my group and I were proud for our completion of assignment 2 nonetheless.

        Despite the above mentioned celebratory accomplishment, my group quickly ( and ironically) realized that we had submitted the wrong version of assignment 2 only after the submission deadline. We then quickly re-submitted the right files and regretted our loss of 5%. From this mistake, my group and I learned to submit the assignment at least an hour ahead, and run our submitted program before the submission deadline. Switching to another topic, Lab 7 was also a challenge. Because I skipped classes in order to have more time thinking about strategy minimax, I missed the lecture about linked list. Hence, when attempting to do the lab on my own, I failed to come up with the implementation for functions such as delete_front and prepend. Furthermore, I had no idea how to delete a middle node and then connect the front node to the back node. Because I had other tests and assignments due in the same week, I didn’t have the proper time to master linked list. And to my dismay, the third question of test 2 involved deleting nodes. 

Me during week 8


        To sum up, last week was like an emotional roller coaster ride. I went from being extremely happy to being disappointed of myself in the end. Although I was able to complete assignment 2, I failed to hand in the assignment on time due to my carelessness. Moreover, my failed time management skills left me unprepared for upcoming tests. Hence, from last week, I realized I had to change my study habits in order to catch up to the missing school work. When submitting assignment 3 in the future, I should submit at least an hour earlier.

Friday, 6 March 2015

Week 8: My impressions of week 7

        Truth be told, I was at the verge of a mental breakdown last week due to Assignment 2. Learning from the mistake of Assignment 1, my group and I decided to tackle the second assignment 10 days earlier, so that we can visit office hours more frequently. However, the office hours proved to be utterly useless as both professors responded to my group’s questions with ambiguity. To my frustration, whenever a question related to strategy minimax was asked, the professors would reply: “I will leave that for you to think about.”  Well, I wouldn’t have attended office hours if I hadn’t already thought about the assignment throughly and get stuck for days. I know my complaint might sound obnoxious and whiny, however, it was difficult to restrain my anger after wasting my class time going to helpless office hours that I had to sacrifice class time for. Now, TippyGameState, TippyMove and GameView were quite easy to write since they are similar to that of a Subtract Square game, and after a few hours, my group and I were able to finish the code. On the opposite, strategy minimax seemed impossible to derive an algorithm. My group and I spent two whole days discussing ideas and solutions to strategy minimax, and whenever we began implementing our ideas, we get stuck writing the code halfway. After multiple fruitless attempts, and after abandoning many ideas, my group decided to attend office hours, which later turned out to be time wasting and useless. 

        Despite facing an unprecedented obstacle, such an unhappy event did not deter me from showing an interest in binary search tree. Due to my fascination and curiosity with such a brilliantly structured tree, I decided to do a quick research on its origin and inventor. From Wikipedia (I know it might not be the most credible and reliable source, but it is the quickest way to research about materials), I learned that the binary search tree (BST) was invented in the 1960 by Windley, Booth, Colin and Hubbard. Each node in a BST contains a maximum of two children, whereby the left node contains a number smaller than the number on the parent node, whereas the right node contains a number larger than the parent node. This structure is very important because it shortens the time of search by half. Relating to the BST is the methods of traversing the nodes. There were three ways of traversal taught in class. The first one was preorder traversal:
Order of traversal: F,B,A,D,C,E,G,I,H
The second one was postorder traversal:
Order of traversal: A,C,E,D,B,H,I,G,F
And the last was inorder traversal:
Order of traversal: A,B,C,D,E,F,G,H,I
At first, the professor’s definition was a bit confusing to understand since it lacked a clear picture. However, after being shown pictorially how to traverse the binary tree in all three orders, my confusion was cleared.

        In conclusion, my impression of last week was horrible due to my inability to write code for strategy minimax. In order to remember the parts where my group and I had problem with, I summarized three major questions regarding strategy minimax:

1. How to derive the scores of the next possible game states using recursions?
2. After computing all the scores, how to select the best score?
3. Lastly, upon determining the best score, how do I associate the score with its corresponding move?


Hopefully, my group is able to solve these problems before the assignment is due.

Friday, 27 February 2015

Week 7: My summary of Abstract Data Types

           Stack, an abstract data type(ADT) was formally introduced to me during week 2 lectures by Professor Danny Heap.  Later, during tutorials and lectures, I also became familiarized with two other ADTs called queue and tree. Although I understood the application of stacks and queue, I still could not understand why they are called abstract data types. Moreover, I was unable to discern the difference of ADTs from other built-in data types such as list, dict, str and tuple, etc,. Hence, in today’s slog, I will be giving a detailed summary on ADT as well as introducing the three examples of ADTs I encountered in class.

          First of all, an abstract data type is a model for a particular data structure defined by the methods it can perform. One thing to keep in mind is that not only can ADT be implemented in python, it can also be implemented in other programming languages like C, java, etc,. This is because ADTs do not contain detailed codes on their implementation. In other words, ADT is concerned only with what the data is representing in general but not the the specifics for its construction.

          Now, I will discuss the definition and purpose of stack. A stack is used to store countless data in an order in which new items are added to the top of the stack, while the top item always gets removed. Hence the acronym LIFO, which stands for “last-in-first-out” is used to describe stack.  Furthermore, stack includes three basic operations. The first method is push(item), where the new data is added to the top of the stack. The second operation is pop() which functions to remove the top (also last) item from stack. And the last method that I was introduced to in class was isEmpty(), which returns True if the stack is empty, else False if the stack contains at least one item. Although Danny did not teach the class all the methods related to stack. I was able to learn them on my own due to my incessant curiosity, After researching online, I discovered that stack also included other operations such as peek(), which returns the topmost item from stack without making any modifications to the stack, and size(), which returns the number of items in the stack. Lastly, real life applications of stack are stacking of plates or books. To see the example calls on these methods, check the link:

          The second ADT that I learned is queue. And I learned it in a tutorial as I was told to write my own code on implementation of queue. Similar to stack, a queue also stores data. However, it operates in a FIFO fashion, which stands for “first-in-first-out”. It includes three basic methods (these are the methods I was asked to write during my CSC148 lab). The first operation is enqueue(item) that adds a new item to the the rear of queue. In other words, as items are being added to a queue, the first item is being pushed to the top. Thus, the last added item is at the bottom of queue, which is different from that of stack (as aforementioned, the last item to be added locates at the top of the stack). The second function is dequeue() that serves to remove the first and topmost item from the queue. Lastly, similar to stack, queue also has a method called isEmpty() that returns True if queue contains no data, and false otherwise. Moreover, queue also has the operation size() that returns the number of items stored in it. The real life applications of queue are people lining up to board an airplane or buy tickets from a ticket booth. Lastly, its example calls can be viewed by clicking the link: http://interactivepython.org/runestone/static/pythonds/BasicDS/queues.html


          The third and last ADT I learned is tree. To begin, similar to stack and queue, tree also stores data. However, it stores data in a hierarchical order. Each item/object is called a node, and we refer to the bottom nodes that happen to branch out the top node as the children of the top node. Furthermore, nodes without any children is referred simply as leaves, whereas, the top most node is called the root. Functions for trees that I was taught in class and tutorials included determining the height of the tree, the number of children, etc,. So far, the class only looked at binary trees (trees where a node only has a maximum of 2 children, called the left and right subtree) in great detail. To sum up, the ADT tree is a real world tree flipped upside down. In my CSC148’s assignment two, I will be combining recursion with tree to assess every possible outcomes of the Tippy Game, and then return the best strategy for the player to win the game. (This idea is required in the class called StrategyMinimax).

          In conclusion, throughout these 7 weeks of class, I learned about abstract data types and its three specific examples — stack, queue and tree. Up until now, the most difficult ADT I learned is tree. However, I have no problem understanding its structure and implementation, since my quizzes about count_leaves is perfect, and I was able to complete the labs regarding trees in a efficient and speedy manner. One thing about tree that I enjoy is its frequent application of recursion. This is because I find writing recursions challenging yet satisfying at the same time after reaching a solution. Hence I was elated to find out that I will be combining both tree and recursion in Assignment 2’s StrategyMinimax. So far, my group has completed the codes for TippyGameState and TippyMove, and we will be writing StrategyMinimax tomorrow. Hopefully, my group can finish the GameState by Monday. Lastly, the advantages of using abstract data types is that ADTs can be reused in future programs. Further,  their implementations can be easily modified without having to make troublesome changes to the program that uses the ADTs. 

Thursday, 19 February 2015

Reading Week: Other CSC148 students' slogs

          During reading week, I had a lot of spare time, so I decided to read other students’ slogs. After going through around 20 other slogs, I have picked my favourite top three bloggers from the 20 blogs I have reviewed so far:


          The authour of the above mentioned blog is my favourite blogger so far. My reasons for liking her (the blogger could be a boy, but I just assumed she is a girl) is that she excel in consistency, writing, and knowledge. Firstly, she updates her slogs weekly with consistency. Not only did she wrote a slog during reading week, but she also wrote two different slogs for week 5! (I think she actually enjoyed writing slogs.) Secondly, her writings are impeccable. I enjoyed reading her slogs because they rarely contain any grammatical error. Furthermore, she always put in a lot of effort in making the slogs seem less boring and more interesting to read for the readers. I liked how she creatively posts interesting yet relevant pictures to complement her slogs. (I think I will adopt her idea.) Lastly, she can clearly define and explain programming concepts. Her explanations on recursion was brilliant and it demonstrated that she actually learned and mastered the material well.

2. http://egq148.blogspot.ca/
          My second favourite blogger is Haley (I think this is her name). Similar to the first blogger, Haley’s writings are excellent (although a grammatical error does appear occasionally) and her slogs are filled with useful information. Although like the first blogger, Hayley is also able to keep the readers entertained, her method of entertainment deviates from blogger number 1. Instead of using pictures to keep things interesting, Hayley writes in an engaging way—its as if she is having a conversation with the reader about her opinions and thoughts on CSC148.

          My third favourite blogger has to be the person with the student number 1001429162 (Since no name is mentioned in this blogger’s blog, I will simple refer to him/her as 162). What I liked about 162’s slog is that he/she has no grammar mistakes (I really enjoy reading writings that contain no grammar mistakes, since I can focus on the content instead of constantly trying to figure out what the writer is trying to say). Also 162’s slogs are really informative in that they contain clear and detailed explanations. In conclusion, I would suggest 162 to upload some pictures along with the writings like the first blogger.


          In conclusion, from reading these three slogs, I now know how to improve my future slogs. Firstly, I would engage the readers by posting interesting pictures and occasionally write in a conversational style. Next, I would present more useful and academic information in my slog, while explaining the difficult concepts in a manner that is easy for readers to understand. Lastly, I will check my grammars constantly in order for readers to smoothly and speedily read through my slogs with clarity.

Friday, 13 February 2015

Week 6: My summary of Object-Oriented Programming concepts

          When I first started programming in high school, I was introduced to the concept of object-oriented programming (a.k.a. OOP). Initially, I had to memorize the definition of OOP in order to pass my computer science exams. However, I had never really understood what OOP means and what it does. Now that I entered university studying in the computer science major, I felt obligated to master all programming-related concepts. So, after doing some research on the internet, I have summarized three important Object-Oriented Programming concepts that programming beginners should become familiarized with.

          First of all, one cannot leave out the definition of object. Now, object means different things under different contexts, however in computer science, it has only one definition. A software object is a model of real world objects, and similarly, a software object also shares two important characteristics, which are: state(or properties) and behaviour. In OOP, objects are created for programming purposes, and their behaviour consists of a set of methods/functions that the certain object performs, whereas the state encompasses all the objects’ properties and their associated values. Interestingly, an object is referred to as the instance of a class. And this leads us to the second OOP concept.

          A class is a representation of a type of object. In other words, it is similar to a blueprint that records all the instructions required to create a specific type of object. It consists of three characteristics:  name, attributes and methods. Since each class is designed for different purposes and contains different attributes, a program that is built to run certain application involves the implementation of countless different objects. Here is an example of a simple class
called Tiger:

Name Of Class: Tiger
Attributes: claws, fangs, golden fur
Methods: eat , roar, run

In this example, the attributes or properties of Tiger are its claws, fangs and fur, while the methods that the class encompasses include eat, roar and run. Since an object is the instance of a class (which is a specific object built from a certain class),  a tiger named Tina is an object created under the class Tiger. And Tina inherits all the necessary attributes and methods from its parent Tiger. Again, this brings me to my next concept.

          The last concept involved around the idea of inheritance of a class, which is the ability of a new class, when created, to inherit all the attributes and methods from an existing class. The new class is called the subclass, whereas, the original class is referred to as the parent class (or super-class). Using my previous example, I can create a new object called FemaleTiger, which is a subclass of the parent class Tiger. Like Tiger, class FemaleTiger also has attributes: claws, fangs, golden fur. Similarly, FemaleTiger also extended all the methods from Tiger: eat, roar and run. Furthermore, an advantage of using OOP is that not only can the subclass inherit functions from its parent class, the subclass also has the ability to add new attributes and methods to itself by overriding existing ones. For instance, subclass FemaleTiger can add another attribute, female, to itself. Furthermore, FemaleTiger can also override the methods it extended from Tiger, and replace them with: drink, give birth, breastfeed, and sit. Hence, my new subclass FemaleTiger will end up looking like this:

Name Of Class: FemaleTiger
Attributes: claws, fangs, golden fur, female
Methods: drink, give birth, sit, breastfeed

Likewise, I can create other subclasses like MaleTiger and BabyTiger:

Name Of Class: MaleTiger
Attributes: claws, fangs, golden fur, Male
Methods: drink, hunt, mate

Name Of Class: BabyTiger
Attributes: claws, fangs, golden fur, tiny stature
Methods: drink, sleep, play


          Although there are more things to say about OOP, such as interface, package,  encapsulation, and polymorphism, the rest is not currently related to my study and their information goes beyond my present knowledge. Thus I will conclude my summary of the OOP and discuss its relation with my Assignment 1. In A1, I was asked to create a generic game state class and later write out a specific game state subclass designated to the game Subtract Square. Despite having understood the general concept of OOP, I failed to properly divide the attributes between the parent and its child class. In other words, I did not properly include certain attributes that are common to all the specific games into the general game state superclass. I also realized that my general game state class mixed some specific attributes from the game subtract square. Hence, I want to remind all the programmers that despite how elementary the concept of inheritance sounds, applying it to programming is no simple tasks. I would recommend everyone to start creating classes with a piece of scrap paper, where they can jot down some similarities between the subclasses, and then include them in the general class. 
   
          In conclusion, OOP has many advantages, such as the ability to provide a clear modular structure for programs. Also, OOP is good for defining abstract data types (such as stack) and it allows easy modification and maintain of existing code as new objects can be created in a efficient manner using inheritance. However, despite all the pros, there are some cons associated with the application of OOP, and they are the fact that the size of object-oriented program tend to be larger, hence the large size slows down the execution speed of programs. Fortunately, recent improvement in compilers mitigated the problem.




Friday, 6 February 2015

Week 5: My impressions of tracing recursion from Week 4

          When I was first introduced to recursion, I could not comprehend the code. The reason was that I had never seen a function that implements itself within its own code before. And when I was asked in class to trace a recursive function, I failed to do so step by step. Fortunately, my confusion was cleared when professor Danny taught the class step by step regarding tracing recursions.



          In order to show my gradual process of ultimately understanding the concept of recursion, I will begin with a recursive function as an example: 


















(Note: this function is taken from additional exercises from Lab #3)
Now, I will trace all four example calls and explain my thinking as I go. 

          To begin, I will trace count_lists([2, 1, 3]). When the list [2, 1, 3] is being inputed into the function “count_lists”, the first “if” is evaluated. Since [2, 1, 3] is indeed type list, the “isinstance()” method is evaluated to True, and the statement “return 1 + sum([count_lists(x) for x in L])” is next to be implemented. Now the trace looks like this:

count_lists([2, 1, 3]) —> 1 + sum([count_lists(2), count_lists(1), count_lists(3)])

This is because the list comprehension applies the function “count_lists()” to every element in list [2, 1, 3]. Since 2, 1 and 3 are non-lists, the “isinstance()” evaluates to false and the code under “else” gets executed instead. As a result, sum([count_lists(2), count_lists(1), count_lists(3)]) becomes sum([0, 0, 0]). Hence, after simplification, the entire trace process will end up looking like this:


          Next,  I will trace count_lists([2, 1, 3, ‘[4]’]). Now, the tricky part of this trace is that ‘[4]’ is type str not type list, hence count_lists(‘[4]’) will return 0 just like the other three ints.


          The previous two examples were really simple and I had no problem understanding them. However, the next two example calls are a bit more complicated to trace since it involves inner-lists. 

The hardest part to understand would be the second line. Hence I will rewrite the first line into this:

1 + sum([count_lists(7), count_lists([2, 1, 3]), count_lists(9), count_lists([3, 2, 4])])

Since 7 and 9 are non-lists, count_lists evaluate to 0. However, because the second and fourth elements are both type lists, count_lists will evaluate to 1. One thing to notice is that count_lists([2, 1, 3]) and count_lists([3, 2, 4]) are simple recursions like example call 1. Since we have traced example 1, there is no need to rewrite it for this example call, and we can simply write 1.

          The last example call is the most complicated of the four. Fortunately, we can skip some intermediate steps when tracing since we did similar ones in the previous three examples. Looking at the example call, I can quickly spot that evaluating count_lists on element 7 and 9 is easy since they simply return 0. Furthermore, because we traced example call 1, we know that count_lists([3, 2, 4]) returns 1 + sum([0, 0, 0]) and hence 1. The most difficult part is evaluating the second element in the example call, since it contains an inner-list within an inner-list: [2, 1, [3, 4], 5].  This is the part where I had trouble the most. In order to fully understand this example call, I decided to break it down into simpler parts. I have already evaluated the first, third and fourth element, thus, I will simply trace count_lists([2, 1, [3, 4], 5]):







Now that I have evaluated the example call by breaking it into simpler parts that I have traced before, I can combine my solution:







          In conclusion, my initial reaction to tracing recursion is confusion. However, after patiently tracing all the practice exercises, I can confidently say that I have understood the concept behind recursion and if I am given a recursive function, I can easily understand its purpose by tracing several example calls. Although recursion requires more memory than iterations and it is slower to run in general,  it is nevertheless useful. The reasons are that:

1. Recursion presents a more elegant and succinct code for implementing a variable number of    nested loops, since the code usually only take up one line 
2. Recursion reduces time complexity 
3. Recursion makes tree-related coding simpler 

Therefore, I find recursion to be a very interesting topic to learn, and I hope that I will get some practice on writing recursive functions. I have a hunch that recursion is going to play a very important role in Assignment 2.



Thursday, 29 January 2015

Week 4: My impression of first few weeks of CSC148

        My impression of the first three weeks differed as the weeks go by. In the first two weeks, everything was simply a review of CSC108. The professor reviewed the concept of class, and the steps required to design a new class (i.e. begin by writing the __init__() and initialize variables). Furthermore, special methods such as str(), eq() and repr() was discussed in further detail. In the later week, the class was introduced to property, which is Python’s built-in function used to intercept all code that assigns to coord and passes that off to _set_coord. Basically, the property mechanism prevents clients/users that use my code from changing certain private attributes. Next, the class learned about one example of abstract data types (ADTs) called stack. Essentially, stack is a data storage mechanism that can store a variety of objects. Furthermore, in a stack, new items can be pushed onto the top of the stack, while items at the top are always removed first.

        So far, the concepts being taught in class can be easily comprehended; however, the topics taught in the third week became significantly more difficult. Before I had the time to reaffirm my knowledge, assignment 1 was being handed down. To my devastation, the one concept that I didn’t grasp thoroughly, inheritance, was implemented heavily in the assignment.  Inheritance is the idea that new classes (called subclass) can be built based on already existing classes (called parent class) by extending the existing class’s methods, or by overriding the methods. When extending methods from the parent class, the subclass automatically inherits the attributes and codes from its parent. Contrarily, overriding existing methods in the parent class means changing the existing methods into something else, and then only implement it within the subclass. Lastly, new methods can be simply added to the subclass. Despite my understanding of inheritance, it is not enough for me to complete assignment 1. This is because I had trouble grouping the methods and attributes that are common to all subclasses into the generic parent class, and leaving the distinct attributes to the subclasses. Even more frustrating was that every time I leave office hour with professor’s feedback, I always ended up making huge modifications to my program. 


        In conclusion, my impression of the first three weeks changed as I gradually learned deeper into the concept of object oriented programming. Classes became more difficult as the Prof began teaching new materials that was never mentioned in CSC108. Moreover, my schedule is thrown into chaos as Assignment 1 came crashing down before I had any preparation. Everything was a frenzy as I try to assimilate into the new learning environment. Before, in CSC108,  the knowledge was being handed down on a silver platter; however, in CSC148, the Professor actually leaves out some materials for us to comprehend on our own.  Hence, my final impression of the first three weeks was a chaotic madness as I tried to get used to new professors, and new and difficult materials.