- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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.

- Related Questions & Answers
- Rectangle Data in Data Structure
- Halfedge data structure
- Deaps in Data Structure
- Quadtrees in Data Structure
- Arrays Data Structure in Javascript
- Stack Data Structure in Javascript
- Queue Data Structure in Javascript
- Set Data Structure in Javascript
- Dictionary Data Structure in Javascript
- Tree Data Structure in Javascript
- Graph Data Structure in Javascript
- Finger Searching in Data Structure
- Skip Lists in Data Structure
- Splay trees in Data Structure
- Solid Trees in Data Structure