Monday, February 2, 2015

Recursion

In last week's lecture we talked about recursion.

Recursion, as you can guess from its name, is a function calling itself. The purpose of this is to divide the problem into smaller problems of same kind. And when it comes to solving problems that are composed of same problems but only smaller, recursion becomes extremely useful.

The most famous data structure that bases on recursion is Binary Search Tree.
For BST, each node has a unique key and all of the nodes are in order (e.g. the key value is always bigger than those of its left subtree and smaller than right subtree). Because of this unique attribute, we can use recursion to do search, insert as well as delete.