Monday, March 31, 2014

Linked Lists

Week 8 was about linked structures.  They were confusing at first, but lectures and the lab made me understand Linked Lists better. A Linked List is a recursive data structure that consists of groups of nodes. Every node is consisted of data (head) and reference (rest) to the next node:


Sunday, March 2, 2014

Recursion

Although it seems a bit complicated at first, Recursion is one of the most useful methods in computer science. It took me a while to understand Recursion, but at the end it's worth it. Doing the Assignment 1 helped me a lot in understanding it.  Basically, Recursion is running the same function over and over again till a condition is met. There's a example of recursion(finding the nested depth of a list):

def nested_depth(L):
    return (1 + max([nested_depth(x) for x in L] + [0]) if isinstance(L, list) else 0)

So what this function does is, it loops over all of the elements of list L and adds 1 every time the element is list, if the element is not list it adds 0.
Overall Recursion is a great method that makes hard tasks easier to solve and save tens of lines of code.