Saturday, March 7, 2015

Week 7, recursion

    In past three weeks we studied more applications and examples of where recursion is used. We learned about trees, and linked lists.
    Trees are a special case of recursion which have leaves which correspond to recursion's base case, and nodes which  have children, which involve recursive code. Pretty much they are a set of nodes() with directed edges connecting pairs of nodes. First node of the tree is called root, and nodes which don't lead to any other nodes are called leaves. All the other nodes (node which is not root and not a leaf) are called internal nodes.  Each parent node can have a certain amount of children, but not more than the value of branching factor is(branching factor is the maximum amount of children a parent node can has), but each child node can have only one parent node(which would be sad if they were people).
    In a way linked lists can be seen as trees, but each parent node can has exactly one child, excluding the leaf(which here is called back) which references to None and has no children. Root is called front in a linked list. We should take great care when using them, and the main reason for that is: while "walking a linked list" you can not go back to a node if you already finished working with it, so you should be sure you won't need this node before you go to the next one. There obviously is a way to get back to it, but it would require starting walking from the beginning of the list and would be unfeasible. In addition there are some cases when you needed to change the back, and declare a new back, but since the old back is not the back anymore, you might not be able to access it in the way you would like to. Linked lists is a powerful, but dangerous tool.

No comments:

Post a Comment