Saturday, 21 February 2015

Week 7 - My Summary of Recursion

One of the most important concepts of the course thus far is recursion. The concept of recursion can be simply stated as "defining something in terms of itself". In order to perform a task in a function, a function can simply call itself on multiple smaller instances of a problem in order to solve a big problem. This makes recursion a very powerful tool, as some of the most complicated problems can be broken into simple pieces, and these simple pieces can be put together like a puzzle to give a solution to the complicated problem, all by recursion.

In class, we have used recursion on trees. One way to think of recursion when working with trees is by assuming that it works for one level of the tree, say level n. If the recursive step solves the sub-problem from n to n+1, then we can assume that the recursive function works for all sub-problems of the tree. The concept of recursion is very similar to induction. We first check for the base case, and when writing recursive code, it is always best to check if the recursive function works for the base case. If it works for the base case, we check to see if the recursive step solves a problem correctly from one level of the tree to the next level, or as we can say, from one node to its children. If the recursive function successfully solves the problem from one level to the next, then we can assume it works for the entire tree.

When writing recursive code, it can be useful to remember a few steps:
1. Write what the function should return in the base case, or what it should return when the tree has no children when working with trees.
2. What it should do when the root of the tree has children.
3. The recursive step.

When the function reaches it's recursive step, the function will break the problem down into smaller pieces and solve the problem for each of it's children, until it finally arrives at the base case. Therefore, it is very important to ensure that the function does exactly what it should correctly for the base case.

So far, I have been working to understand the exercises in the lab hand outs and understand the examples that have been done in class by drawing out the trees, tracing through examples, and thinking about what I would need to do at each step in order to successfully implement a recursive function. I look forward to becoming a master at recursion in the coming weeks.

Saturday, 14 February 2015

Week 6 - Summary of Object Oriented Programming Concepts.

This week, I will give a brief summary on Object Oriented Programming. So far in CSC148, everything we have covered has to do with Object Oriented Programming. Object oriented programming is when programmers get to choose what data types are used, which data structures are used, and to apply functions and operations to those data types and data structures. A simple example of this is me creating a list of my grades in the form of numbers (that represent percentages), using a for loop (an operation) to iterate through each element in the list to sum the numerical grades together, storing the sum in a variable, and dividing it by the length of the list to come up with an average. This would return a float representing an average percentage grade. In this example, I got to choose the data structures that I want to work with and the operations I want to perform on the data structures.

Some main concepts of object oriented programming we have learned so far in this course are classes and subclasses. Classes are objects that define a set of attributes that characterize objects of the class. For example we can write a class called GameState, in which we would define a method called state_turn, which would return a string telling the player of any game whose turn it is. This class would contain multiple attributes that perform different operations relating to the play of any game. A subclass is a class that inherits the methods of a parent class, and may contain additional methods relating to something more specific. For example, we may have a subclass called TicTacToe(GameState), where the class GameState is the parent class and the subclass would be TicTacToe. The subclass TicTacToe would inherit all the methods of GameState, which contain methods relating to the play of any general game, and the subclass may contain additional methods that may relate to the game TicTacToe.

At this point in the course, I feel very comfortable with the object oriented programming concepts we have learned in this course. One thing that I can continue doing to improve my performance in the course is by starting to work on the lab exercises ahead of time. This week, I did not perform well on the quiz, but after completing the lab exercises today, I realize how easy the quiz was. Also, I realized that I need more than two hours to go through all the exercises in the lab and to understand in depth how each piece of code performs operations. By starting lab exercises Wednesday night, I will have sufficient time to understand all the material in the lab handout, thereby improving my performance in the quizzes.


Saturday, 7 February 2015

Week 5 - Experiences and Summary of Abstract Data Types.

This past week was an interesting week. The lectures ended quite early, and we were introduced to two new Abstract Data Types in Python. We were introduced to Stacks and Queues. The concepts weren't too difficult to grasp during lecture. I learned that a stack is a collection of items, meaning that it has multiple elements. This can be compared to lists and dictionaries, which can also contain multiple elements. We talked about some interesting basic operations that stacks have.
These include:
1. Stack(), which creates a new stack. New stacks are usually stored in a variable, so if I were to create a new stack, I would write: stack = Stack().
2. is_empty(), which checks to see if the stack has any elements. This method has a boolean return type, and returns True if and only if the stack has no elements. When calling this method, I would write: stack.is_empty().
3. push(item), which pushes an item to the top of the stack.
4. pop(), which removes and returns the item at the top of the stack.

Stacks follow the last in first out protocol. This means, that whatever has been pushed last is the first to be removed when we choose to remove an element from the stack.

Queues, however, follow the first in first out protocol. Basic operations of Queue include:
1. Queue, which creates a new queue.
2. enqueue(), which adds an item to the back of the queue
3. dequeue(), which removes an item from the front of the queue.

Queues follow the first in first out protocol. This means that whatever was added to the first in the queue is the first to be removed when we choose to remove an element from the queue.

I did not perform well in the lab as I hoped I would. I showed up to the lab on time and I did the basic exercises in the lab that were assigned. I got a basic understanding of how to write methods in class Stack and class Queue, and I got a basic understanding for their operations. However, I did not do the additional exercises, which required us to trace what some functions implemented in the lab would do with complicated lists (the functions being stack_list and queue_list). Regardless of what the operations of those functions are, while doing the quiz, I realized that to gain a solid understanding of what is required in the course, I should work on the additional lab exercises. This is what I will do from now and on to improve my performance in the lab quizzes and to gain a solid understanding of what is required in the course.

My experiences in the course is similar to that of the blogger with the link: (http://2ne1bigbangexosuperjuniorbts.blogspot.ca/2015/02/week-5-slog.html). Similar to this blogger, I too was excited when I heard that we would be allowed an aid sheet for the test, but while writing the aid sheet, I felt as though what I am writing is already in my brain. I felt as though the best way to prepare for the test is by re doing lab questions for practice, and working on the additional lab exercises. Similar to the blogger, I didn't read the aid sheet during the test because everything was already in my brain. I agree with the blogger when he/she says that the purpose of allowing an aid sheet is to help us review for the test, not to help us cheat on the test by looking at a secondary source.

I am looking forward to a fantastic next week!