Friday, February 27, 2015

Week#7 Recursion II

Continue on Recursion

Tree
After reading week, we continued the lectures about recursion, however, the lecture focused on a different class named BTNode, a generic Tree design. In my opinion, Tree enables us to learn the recursion method more visualizable. We can trace the steps in a specific diagram.


Initialize of the BTNode

Compared with the lectures before reading week, the codes we wrote in this week’s lecture seem to be more complicated. The reason is that parents and leaves should not only be run, but also be evaluated whether it is valid and the codes should be calculated in a specific order. All these requirements needs more specific methods to be written in one class.


evaluate method
In evaluate method, the return result is the value after being calculated by the int and str provided in the tree. And the simplest situation is when the node is a leaf, which would involve another method in the class. However, the recursion steps are similar with before. But the calculation in the recursion steps would make us confused and lost in the position of tracing steps.

Friday, February 13, 2015

WEEK#6 Object-oriented Programming Concepts

WEEK#6 Object-oriented Programming Concepts


Stack: in a stack, you remove items in reverse order you insert them, so the first item removed is the most recently-added.
ADT(abstract data type): An ADT describes how it stores data, and what operations(methods) one can perform on this data.
This is abstract because there is no code required to understand an ADT.

Class

Class: A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members(class variables and instance variables) and methods, accessed via dot notation.
Class variable: A variable that that is shared by all instances of a class. Class variables are defined within a class but outside any of the class’s methods. Class variables aren’t used as frequently as instance variables are.
Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.
Inheritance: The transfer of the characteristics of a class to other classes that are derived from it.
Method: A special kind of function that is defined in a class definition.
Object: A unique instance of a data structure that’s defined by its class. An object comprises both data members (class variables and instance variables) and method.
Operator overloading: The assignment of more than one function to particular operator.
Exception: the purpose of the Exceptin is to stop the program woth a meaningful message if there is an advertent executin path that would return NoneType.

Recursion

Recursion means “defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective.
Data Structure:The organization of data for the purpose of making it easier to use is called a data structure
 recursive call : The statement inside the function definition in which the function calls itself is known as the recursive call.
base case: It does not lead to a recursive call: the case where the element is not a (sub-) list. Without a base case, you’ll have infinite recursion, and your program will not work.
## base case: A branch of the conditional statement in a recursive function that does not give rise to further recursive calls.
## infinite recursion: A function that calls itself recursively without ever reaching any base case. Eventually, infinite recursion causes a runtime error.
## recursion: The process of calling a function that is already executing.
##recursive call: The statement that calls an already executing function. Recursion can also be indirect — function f can call g which calls h, and h could make a call back to f.

## recursive definition: A definition which defines something in terms of itself. To be useful it must include base cases which are not recursive. In this way it differs from acircular definition. Recursive definitions often provide an elegant way to express complex data structures, like a directory that can contain other directories, or a menu that can contain other menus.

Friday, February 6, 2015

WEEK 4 RECURSION

What we learned in week 4 is recursion on python, which is a typical method to trace every step ran in a function call with only known the body part. What's more importantly, recuision illustrates the function is used again and again in just one particular function call. The most basic thing in recursionis carefully finding out every step without docstring description. The sum_list described in the lecture can be a basic example for recursion.

The attributes in the sum_list is a list, however, it could be a nested list. Therefore, sum should be used when the elements in the list are all integers. Whenever the element is a list, sum_list should be used again. It won't stop tracing until the elements are all not list.

For example, we need to trace this call.
This screenshot clearly illustrates how this call being traced step by step.