Saturday, March 1, 2014

Week 7: Linked Lists and Recursion

     After the week on Tree traversing, we now learned on how to make pre-order, in-order, and post-order to make a sequence of leaves in the trees. This week, there are lists of numbers and we learned to prepend values in the class. Generally, with arity of only 1 and a continuous branching of lists end up creating nodes with only 1 child, a list of values. This also shows that empty lists are more than just empty lists, that the head can trace or refer to None and preserve the id of the list using prepending of the head of the list.
    I worked on prepending and replacing old elements with new ones by creating a Queue class in the labs, and had to refer to the Tree class ADT to understand the rules of Tree classes and their special functions like __eq__, __repr__, __contains__. I suspect it is the same on learning trees, there isn't much an application to recursion, but there is new information regarding on Tree manipulation
For example:

Recursive functions call back to solve smaller problems to get to the big one:

def  function(a):
    if a == 0:
         perform first action    // A normal base case where 0 or 1, something simple first used
   elif a != 0:
        use function(a-1)     // the previous function that was calculated is applied
Then this keeps up until a actions are completed.
This is mathematical induction or proving mathematical/engineering concepts..

With Linked Lists, the classes construct an empty list, with values of a head then growing more nodes at the end and continues on until the end. IT kinda looks like a growing centipede

Example:      
 """ Beginning Node and Licked lists in this section. """
 
    def __init__(self, item=None, further=None):
        self.item = item
        self.further = next
 
    def __str__(self):
        return str(self.item)

This example shows for every node node n is in class Node(n) and will continue by using next to move on to the next node until all n nodes are completed.

No comments:

Post a Comment