Monday, March 3, 2014

Recursion

One of the recent topics I have learned was 'Recursion'. Recursion is basically a function calling on itself, creating a loop. To stop the recursion, we have a base case which is basically a condition to know when the loop to stop. In class, the lecturer is usually writing recursions in comprehensions, mainly list comprehensions, which I'm still trying to get a full grasp on. I think writing recursions in a body is more for me, just because I'm more experienced with it.

We've also learned about recursive structures. One being 'Trees', as my previous post has partially mentioned. Tree's being structures that resemble what the name suggests. They have nodes and paths, and the top primary node which is called the 'root', which is the first node of all pathways. All trees have a unique path leading to a certain node. Nodes with no 'child', or leading to another nodes can be called a 'leaf'.

How recursion is used in these structures is how we access them, there are three ways to access them called 'Traversals'. There are three traversals: Pre-order, In-order and Post-order traversals. Pre-order meaning going from root to left-subtree to right sub-tree. In-order going from left-subtree, root and to right-subtree. Finally post-order going from left-subtree, right-subtree and root. All of these traversals use recursion to work, checking if each node has subtrees or is just a leaf. That's a bit of what I learned of recursion and some ADT's that use recursion.


No comments:

Post a Comment