1. object, oriented programming concept
- class
- subclass
1. declaring that we're extending it... *
class NewClass(OldClass):*
...
2. add methods and attributes to specialize*
3. other methods and attributes are searched for in superclass*
(* are from Prof Heap's vanilla PPT)
2. Recursion
We spent more than half of the semester to discuss issues with recursion. Recursion is very powerful. We firstly learned how to trace recursion. What we usually do is starting from the simplest example and skipping similar steps to get more complicated cases.
When it comes to writing recursion codes, I found myself struggling for a quite long time. Actually, there is no need to trace the recursion during the time you write the codes.
I found Christian makes a useful summary on his slog.
Recursive step for a list
return sum([sum_list(x) for x in L])
Recursive step for a tree
return sum([leaf_count(child) for child in t.children])
And in the assignment 3, I used a for loop to get the recursion and we even make the turtle recursion.
3. Trees
I leaf: node with no children *
I internal node: node with one or more children*
I subtree: tree formed by any tree node together with its
descendants and the edges leading to them.*
I height: 1 + the maximum path length in a tree. A node also has
a height, which is 1 + the maximum path length of the tree
rooted at that node*
I depth: Height of the entire tree minus the height of a node is the
depth of the node.*
I arty, branching factor: maximum number of children for any node. *
(So a tree with height 3 and arty 3 has at least 3 nodes)
(* are from Prof Heap's vanilla PPT)
We even
4. Tree traversal
Therefore, the Preorder traversal of the above tree will outputs:
7, 1, 0, 3, 2, 5, 4, 6, 9, 8, 10
Inorder traversal: To traverse a binary tree in Inorder, following operations are carried-out (i) Traverse the left most subtree starting at the left external node, (ii) Visit the root, and (iii) Traverse the right subtree starting at the left external node.
Therefore, the Inorder traversal of the above tree will outputs:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Postorder traversal: To traverse a binary tree in Postorder, following operations are carried-out (i) Traverse all the left external nodes starting with the left most subtree which is then followed by bubble-up all the internal nodes, (ii) Traverse the right subtree starting at the left external node which is then followed by bubble-up all the internal nodes, and (iii) Visit the root.
Therefore, the Postorder traversal of the above tree will outputs:
0, 2, 4, 6, 5, 3, 1, 8, 10, 9, 7
(things above are from the link http://datastructuresnotes.blogspot.ca/2009/02/binary-tree-traversal-preorder-inorder.html )



