Friday, February 27, 2015

Week7-Thoughts on Abstract Data Type

Abstract Data Type (ADT) is an abstract data type is a model for a particular data structure defined by the methods it can perform. It can be implanted into not only python, but also other programming languages such as java and C++. We learnt three kinds of ADT in CSC148, and I want to introduce them separately.

The most basic form of ADT is stack. Stack allows us to add new items to the top of the stack, then, items are removed from top to bottom. In other works, items are added and deleted based on the rule of “last-in-first-out”. A stack involved three basic operations: push() enables new data to be added, pop() removes the top item, and isEmpty() determines whether everything is removed. The second kind of ADT we learnt is Queue. It is very similar to Stack, but its first added element is removed first. Similarly, A Queue also involved three basic operations: enqueue() enables new data to be added, dequeue() removes the bottom item, and isEmpty() determines whether everything is removed. The third ADT I learned is tree. Like stack and queue, tree also stores data. However, Tree stores data in a hierarchical order. Item in a tree is called node, and bottom nodes that branch out top nodes are children of the top nodes. And nodes without any children(are not parents) are referred as leaves. And finally, the node that the very top is called root.

Tree is the most difficult Abstract Data Type among the three. I also think that it is the key to solve the following assignment, because there are so many variations that can be developed based on it.


Thursday, February 19, 2015

Week6-Object-Oriented Programming

Object-oriented programming is a method that represent real life systems and aims to solve real life problems. The name of Object-Oriented Programming is pretty self-explanatory. OOP is a type of programming that revolves around devising procedures by using a variety of independent and co-ordination objects. It also involves concepts such as class, objects, inheritance, instance, instantiation, message passing as so on.

Python is a classical Object-Oriented Programming language. What are objects In Python? They can be Python built-in data types, such as strings, boolean, and list.  They can also be “classes” that are created by programmers. Class can also contains various “methods” that perform corresponding jobs. Moreover, we can create subclasses that inherit the characteristics of the superclass and perform different jobs by adding methods.  For example, we can create a class called “food” which is defined by the eatable characteristic. This means that subclasses of “food” such as “fruit”, “meat” and “vegetable” all shares the characteristic of being eatable. 


In the lecture, Prof. Heap created a parent class called 'Shape', and two classes of 'Square' and 'Triangle' which inherit the variables of 'a' and 'b' from the 'Shape' class. One thing that I find important here is that the parent class raise an error when it is called to perform a function of its children.  
 def get_area(self):
        ''' (Shape) -> float

        Return the area of self.

        >>> from square import Square
        >>> Square(0, 0, 10).get_area()
        100.0
        '''
        raise NotImplementedError('Need a subclass')

This is my basic understanding about what Object-oriented programming is. My classmate Christian has a deep understanding about the topic. Her writing of 'Week 6 Object-oriented programming concepts'(http://christiangarciacsc148.blogspot.ca/2015/02/object-oriented-programming.html) and 'Week 4 Classes and Subclasses'(http://christiangarciacsc148.blogspot.ca/2015/02/csc148-week-4-classes-and-subclasses.html) helped me a lot in understanding basic ideas of  
Object-oriented programming  as well as the purpose of this course. 

Wednesday, February 4, 2015

Week5-Tracing Recursion






Recursion is a way of finding solutions by breaking down the solution into smaller parts and build up the final solution by the smaller parts. In other words, it is the process of repeating items in a self-similar way.

When tracing most recursive functions, there is winding and unwinding part. The "winding" part occurs as the recursion heads to the base case, and the "unwinding" part occurs when the recursion returns back to the original call. 

One thing that is important to realize is that analyzing a few base cases can help give a better understanding of the big image.  

I understand recursion functions as a method to separate the unwinding functions in to multiple small winding parts.  And since the winding part to be much easier, the question becomes solvable. Therefore, the most important idea behind recursion to me is to repeat the same task in various depths. 

Also, I found that recursion is just like while loop and for loop because they are all about repeating a calculation for multiple time. Here is an example of the three.