Recurrence relations are a tool for analyzing recursive algorithms.
An example you may be familiar with is MergeSort? . A recursion diagram for mergesort looks like this:
Define T(n) to be the time taken to mergesort n elements (neglecting constant factors). Then T(n) satisfies the following:
The above relation between T(n) and T(n/2) is called a recurrence relation.
The relation is true because the time to mergesort an array with n elements equals the time to mergesort an array with n/2 elements, plus the time to mergesort another array with n/2 elements, plus n.
Similarly, a recurrence relation for the time to do a binary search on an array of N elements is:
That is, a binary search in an array of size N does constant work, then recurses on one of the two halves of the array (a problem of size N/2).
The recursion diagram in this case just looks like this:
N | N/2 | N/4 | ... | 4 | 2 | 1
In this case, the work associated with each node of the tree is 1, and the depth of the tree is log(N), so the total work done is O(log N).
The number of single-disc moves to transfer N discs in the TowersOfHanoi? problem satisfies:
The corresponding recursion diagram is a complete binary tree of depth N, and for each node, 1 disc is moved. Thus, the total number of moves made to transfer N discs is 2N-1.