Sunday, 2 March 2014

Recursion... and Some Other Stuff

Well... apparently we're supposed to write a paragraph about recursion this week so let's get on with it. The idea behind recursion is to keep on repeating a function until a "base case" is reached. For example the most common recursive method we used was calculating the sum of a nested list. The function would keep on running itself as long as the next element was a list and eventually, you would reach a case where instead of a list, you would hit a numerical value of some kind. That numerical value would be the base case in this situation and the method would begin going back up the recursive steps you took to reach that base case. The idea of a recursive method is that you can break up a very complex problem by breaking it down into smaller parts and analyzing them and then moving back to the bigger parts while knowing what the smaller parts it consists of will return. We used recursion recently in our trees as well by analyzing each node and its children until we eventually reached a node that did not have any children. That is when we knew that it was time to end the recursive calls and begin going back up the recursive steps.

That's enough of recursion for now, time to go over what we learned in the lectures this week. This week we went over LinkedLists and it's slightly different then how we did it in Java. In Java, we had a head and a tail, similar to how we're dealing with LinkedLists now but instead of just pointing to an empty LinkedList object, we had the last item in a LinkedList pointing to a null. We also did something in Java back then called a Doubly LinkedList and it had both a ending null but also a head null so the LinkedList could be read both ways. The slight difference with what we learned now is that a head has 1 value and everything that is left is in the tail. In Java, we had a node pointing to a node, pointing to another node until that last node pointed to null. It's about the same thing but it was a bit confusing at first for me to see how the tails of the LinkedList worked.

No comments:

Post a Comment