Recurrence Equations in Data Structure

During analysis of algorithms, we find some recurrence relations. These recurrence relations are basically using the same function in the expression. In most of the cases for recursive algorithm analysis, and divide and conquer algorithm we get the recurrence relations.

Here we will see one example of recurrence equation by the help of some examples. Suppose we are using the binary search technique. In this technique, we check whether the element is present at the end or not. If that is present at middle, then the algorithm terminates, otherwise we take either the left and right subarray from the actual array again and again. So in each step the size of the array decreases by n / 2. Suppose the binary search algorithm takes T(n) amount of time to execute. The base condition takes O(1) amount of time. So the recurrence equation will be like below −

$$T(n)=\begin{cases}T(1) & for\:n \leq 1\T(|\frac{n}{2}\rvert)+c & for\:n > 1\end{cases}$$

Similarly, if we choose another example like merge sort, then in that case we divide the list into two parts. This division is taking place until the list size is only 1. After that we merge them in sorted order. The merging algorithm takes O(n) amount of time. So if the merge sort algorithm is taking T(n) amount of time, then by dividing it into two halves, and do the same task for each of them, they will take T(n/2) and so on. So the recurrence relation will be like below −

$$T(n)=\begin{cases}T(1) & for\:n = 1\2T(\frac{n}{2})+cn & for\:n > 1\end{cases}$$

We can solve these equations using different methods, like substitution, recurrence tree method, and some special kind of recurrence relations can be solved using Master methods.

Updated on: 10-Aug-2020


Kickstart Your Career

Get certified by completing the course

Get Started