Saturday, 21 February 2015

Slog 4

This week's lecture talks about a new abstract data type, which is tree. Tree can stores data in nodes and each child node is connected by a parent edge, to be noticed that, each node has only one parent node. Moreover, the path of a tree is the number of nodes, and the length is the number of edges. Tree is usually used to represent a hierarchical system. Furthermore, to write a class for tree, it is very important to divide it into two cases. Firstly, writing down the base case for the use of the tree. Secondly, writing the function on special case and then run recursion base on it. Consequently, tree is a very useful way to store data
 

Sunday, 8 February 2015

CSC148 Slog 3

This week's lecture is mainly about recursion, which is a function calling itself in its body. And this method is useful for solving problem such as with duplicate same features, for example, calculating the sum in [1,[1,2],[[[1]]]]. In this example, square bracket appears many times and some of it is useless. Therefore, it is more efficient to solve this kind of problem with recursion. However, this kind the of problem can also be solved by using for loop, but recursion is easier to understand and trace bugs. Furthermore, during the trace of recursion, we can simply trace the easy example first, and then we can conclude the result of complicated examples by the previous result. For example, if we know the input of integer will return 1, and a list will put all integers in that list into integer, then we can conclude that the list will return number of integer in that list. In conclusion, recursion is a very useful method.

Saturday, 7 February 2015

CSC148 blog2

In the first few week, CSC148 covers many knowledge, such as the recap of class, and  special methods in the class, and brief introduction of abstract data type. Importantly, inheritance is completely new to me and it is one of the most significant topic in CSC148. To begin with, inheritance separates two kind of classes, parent class and children class. To be more precisely, parent class is the supper class that including general methods, such as init, str, eq. However, some specific methods cannot be written in the parent class because it is going to be different cases diver circumstance. For example, employ can be divided into hourly employe and salaried employe. Therefore, they are going to be paid differently and methods needs to be written in specific child class. Moreover, exception is mentioned in inheritance. Firstly, exception is used to ignore some errors because it is no need to care about them but programmer still wants the code works. For example, there could be a amount of pay in the employe parent class, but it cannot be written so far due to lack of information on how employe is paid. Therefore, programmer just need to write 'Not ImplementError' under the methods, and the code will run it without errors and programmer can add more information in the children class. In conclusion, inheritance is a very important skill for designing class.