How to solve Tn Tn - 1 n
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In the realm of algorithm analysis, recurrence relations often emerge as tools to describe the performance of recursive algorithms. The recurrence relation , in particular, is a quintessential example of an arithmetic sequence in algorithm analysis often seen when evaluating simple recursive algorithms. This article will detail the solution for this recurrence using technical explanations and examples.
Understanding the Recurrence
The recurrence suggests that the value at depends linearly on its predecessor with an additional increment of . This is emblematic of an algorithm that adds a linearly increasing amount of work at each stage. Below is a step-by-step explanation to solve this recurrence with initial condition :
Step-by-Step Solution
1. Setup of the Relation
Given the recurrence , we start with the base case . The task is to express explicitly without recursion.
2. Unrolling the Recurrence
• Start from the recurrence and unwind it:
• This clearly shows that is equivalent to the sum of integers from to .
3. Summation Formula
• The formula for the sum of the first natural numbers is:
4. Verification
• Substitute into the formula to verify the base condition:
• Consider :
• This matches the unrolled version as well:
Evaluating Complex Scenarios
Given the simplicity, the solution enables quick calculations for larger . For example, for , would be:
Technical Explanation
Time Complexity Implications
The expression $T(n) = \frac\{n(n + 1)\}\{2\}$ is $O(n^2)$. This quadratic complexity arises because each call incurs work proportional to , leading to a cumulative work of the order . As such, algorithms that follow this recurrence are not ideal for larger input sizes when optimum performance is critical.
Implementing in Code
Here is an example implementation of how this recurrence might be solved iteratively rather than recursively:
Related reading
- How to sort a collection by date in MongoDB?
- How to sort a list of lists by a specific index of the inner list?
- How to sort a list of strings?
- How to sort a list of strings numerically
- How to sort an array of integers faster than quicksort?
- How to sort faster than n log n given a strong condition on the list?
- How to sort a List/ArrayList?
- How to Sort a List<T> by a property in the object

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.