Discrete StructureUnit 715 min read
Recurrence Relations & Sequences: Solving, Trees, and Real-World Models
Unit 7 of Discrete Structure covers solving linear recurrence relations (homogeneous/nonhomogeneous), generating functions, Fibonacci sequences, and applications in algorithms (e.g., divide-and-conquer), financial models (e.g., loan amortization), and combinatorial counting (e.g., binary tree nodes). You’ll learn to de
Core Concepts: What is a Recurrence Relation?
A recurrence relation defines each term in a sequence based on previous terms and a fixed rule. Unlike closed-form formulas (e.g., ), recurrences express terms recursively.
Types of Recurrences
- Linear Recurrence: Each term is a linear combination of prior terms. Example: .
- Nonlinear Recurrence: Involves products, exponents, or nonlinear functions. Example: .
- Homogeneous vs. Nonhomogeneous:
- Homogeneous: No extra terms (e.g., ).
- Nonhomogeneous: Has a "source" term (e.g., ).
Why Solve Recurrences?
Recurrences model:
- Algorithms: Merge sort’s .
- Finance: Loan repayments (amortization schedules).
- Biology: Population growth (e.g., Fibonacci rabbits).
- Computer Networks: Packet routing delays.
1. Solving Linear Homogeneous Recurrences with Constant Coefficients
Step-by-Step Method
For a recurrence like :
- Find the characteristic equation: Replace with : . Simplify to .
- Solve for roots :
- If roots are real and distinct: General solution is .
- If roots are equal (): Solution is .
- If roots are complex (): Use Euler’s formula: , where and .
Worked Example: Fibonacci Sequence
Recurrence: , with , . Characteristic equation: → Roots: . Solution: Using initial conditions:
- → .
- , where , . Thus, , . Closed-form (Binet’s formula):
Visual: Fibonacci Tree Growth
graph TD
A["F_0 = 0"] --> B["F_1 = 1"]
B --> C["F_2 = F_1 + F_0 = 1"]
C --> D["F_3 = F_2 + F_1 = 2"]
C --> E["F_4 = F_3 + F_2 = 3"]
D --> F["F_5 = 5"]
E --> FReal-world tie-in:
- Pathao’s ride-matching: The number of possible ride assignments grows like Fibonacci numbers when matching drivers to passengers in a greedy algorithm.
- Ncell’s call routing: The optimal path for a call to traverse switches can be modeled recursively, with Fibonacci-like growth in worst-case scenarios.
2. Nonhomogeneous Recurrences: The "Particular Solution" Trick
For recurrences like :
- Solve the homogeneous part (as above).
- Guess a particular solution based on :
- If (constant), try .
- If (polynomial of degree ), try of degree (unless is already in the homogeneous solution; then multiply by ).
- If , try (where is the multiplicity of as a root of the homogeneous equation).
Worked Example: Loan Amortization (Nepal Bank Loan)
Recurrence: Monthly payment on a loan of at interest rate : This is nonhomogeneous: . Homogeneous solution: . Particular solution: Guess (constant). Substitute: → . General solution: Initial condition: → . Final formula: Interpretation:
- The loan balance grows exponentially if no payments are made ().
- The term represents the "present value" of the payment stream.
Visual: Loan Balance Over Time
Real-world tie-in:
- Nepal’s NMB Bank: Uses this exact model to calculate monthly EMI payments for home loans. For a 10-year loan at 8% annual interest, the recurrence ensures the loan is paid off in exactly 120 months.
- eSewa’s microloans: Even small loans (e.g., ₹50,000) use recurrence-based amortization to split repayments into weekly installments.
3. Generating Functions: A Powerful Tool
Generating functions convert recurrences into algebraic equations. For a sequence : Steps to solve:
- Write the recurrence in terms of .
- Solve for .
- Extract coefficients using Taylor series.
Worked Example: Catalan Numbers (Binary Tree Count)
Recurrence: , with . Generating function approach: Multiply both sides by and sum over : The right side is (convolution of sequences). Thus: Solve the quadratic: Take the negative root (for convergence): Closed-form: Using the binomial expansion of :
Visual: Binary Tree Structure (Catalan Numbers)
Real-world tie-in:
- Daraz’s order fulfillment: The number of ways to arrange items in a warehouse’s "pick-and-pack" sequence (where some items must be grouped) follows Catalan numbers. For example, if you have 3 items (A, B, C) with constraints like "A must come before B," the valid sequences are counted by .
- YouTube’s recommendation algorithm: The structure of nested playlists or "watch next" suggestions can be modeled using Catalan trees to optimize user engagement.
4. Recurrences in Algorithm Analysis
Master Theorem for Divide-and-Conquer
For recurrences of the form :
- Compare with :
- If : .
- If : .
- If and : .
Worked Example: Merge Sort
Recurrence: . Here, , , . Compare with : Since , the second case applies:
Visual: Merge Sort Recurrence Tree
graph TD
A["Merge Sort Recurrence"]
A --> B["2T(n/2) + O(n)"]
B --> C["T(n/2)"]
B --> D["T(n/2)"]
C --> E["2T(n/4) + O(n/2)"]
D --> F["2T(n/4) + O(n/2)"]
E --> G["T(n/4)"]
F --> H["T(n/4)"]Real-world tie-in:
- Pathao’s driver assignment: When matching drivers to passengers, a divide-and-conquer approach (split drivers/riders into halves, recursively match) has the same complexity as merge sort. This ensures efficient matching even during peak hours (e.g., 5 PM in Kathmandu).
- NTC’s network routing: The optimal path for data packets in Nepal’s fiber-optic backbone uses recurrence-based algorithms to minimize latency, similar to merge sort’s balanced splitting.
5. Solving Recurrences with Trees
Recursion Trees
Draw a tree where:
- Each node represents a subproblem.
- The root is .
- Children are the recursive calls.
Sum the costs at each level to find .
Worked Example: Strassen’s Matrix Multiplication
Recurrence: . Recursion tree:
- Level 0:
- Level 1:
- Level 2:
- ...
- Total cost: Geometric series sums to .
Visual: Recursion Tree for Strassen’s Algorithm
graph TD
A["T(n)"] --> B["7T(n/2) + O(n²)"]
B --> C["T(n/2)"]
B --> D["T(n/2)"]
B --> E["T(n/2)"]
B --> F["T(n/2)"]
C --> G["7T(n/4) + O(n²/4)"]Real-world tie-in:
- Google Maps’ route optimization: When calculating the shortest path between multiple points (e.g., a tour of 10 landmarks in Pokhara), Strassen’s algorithm reduces the complexity of naive matrix multiplication to , speeding up real-time navigation.
## In the Real World
| Company/Product | Recurrence Idea Used | How It Works |
|---|---|---|
| Pathao (Nepal) | Divide-and-conquer matching () | Splits drivers/riders into halves to match efficiently during peak hours. |
| NMB Bank (Loan EMI) | Nonhomogeneous recurrence () | Calculates monthly payments to ensure the loan is cleared in fixed terms. |
| Daraz (Order Fulfillment) | Catalan numbers for sequence constraints | Counts valid packing sequences when some items must be grouped. |
| Ncell (Call Routing) | Recursion trees for optimal paths | Minimizes hops in call routing by balancing load across switches. |
| YouTube (Recommendations) | Binary tree structures (Catalan numbers) | Organizes nested playlists to maximize user engagement. |
| NTC (Fiber-Optic Backbone) | Merge-sort-like balancing | Ensures data packets take optimal paths through Nepal’s network nodes. |
## Exam Tip
What Examiners Look For
Correct Form of the Characteristic Equation:
- For , the equation must be .
- Common mistake: Forgetting to include all coefficients (e.g., writing ).
Particular Solutions for Nonhomogeneous Recurrences:
- If , guess .
- If 5 is not a root of the homogeneous equation, .
- If 5 is a single root, .
- If 5 is a double root, .
- Common mistake: Using when 5 is a root (forgets to multiply by ).
- If , guess .
Generating Functions:
- Always include the initial condition (e.g., ) when solving for constants.
- Common mistake: Skipping the step and losing marks.
Algorithm Analysis:
- For the Master Theorem, correctly identify , , and .
- Example: → , , .
- Common mistake: Misapplying the theorem (e.g., using case 1 when case 2 applies).
- For the Master Theorem, correctly identify , , and .
Real-World Applications:
- Always tie your answer to a concrete example (e.g., "This recurrence models Pathao’s driver matching during Diwali").
- Common mistake: Giving a generic answer without context.
Mark Distribution in TU Exams
| Task | Marks | How to Score Full Marks |
|---|---|---|
| Solve a homogeneous recurrence | 5 | Correct characteristic equation, roots, general solution, and initial conditions applied. |
| Solve a nonhomogeneous recurrence | 7 | Homogeneous + particular solution + correct guess for . |
| Generating function approach | 6 | Correct setup, algebraic manipulation, and coefficient extraction. |
| Algorithm analysis (Master Theorem) | 5 | Accurate identification of , , , and correct case application. |
| Real-world connection | 2 | Explicit link to a Nepalese company/product (e.g., "This models Ncell’s call routing"). |
Past Exam Pitfalls to Avoid
Ignoring Initial Conditions:
- Example: For , , the solution is , not .
- Fix: Always substitute initial conditions to find constants.
Incorrect Particular Solution Guess:
- For , guessing is wrong because 3 is not a root of the homogeneous equation.
- Fix: Guess with (since 3 is not a root).
Misapplying the Master Theorem:
- For , the correct case is case 2 (), not case 1.
- Fix: Compare with carefully.
Forgetting to Simplify:
- Example: Leaving the solution as without substituting and .
- Fix: Always simplify using initial conditions.
Quick Revision Checklist
Before the exam, verify you can:
- Write the characteristic equation for any linear homogeneous recurrence.
- Solve for roots (real, repeated, complex).
- Guess particular solutions for common (constants, polynomials, exponentials).
- Apply the Master Theorem to algorithm recurrences.
- Draw a recursion tree for a given recurrence.
- Connect at least two real-world examples to recurrences (e.g., Pathao + NMB Bank).
Final Worked Problem (Exam-Style)
Question: Solve the recurrence relation with initial conditions , .
Solution:
- Characteristic equation: → → Repeated root (multiplicity 2).
- General solution: .
- Apply initial conditions:
- → .
- → → .
- Final solution:
Real-world tie-in: This models the growth of a viral marketing campaign (e.g., Daraz’s "Refer and Earn" scheme), where the number of new users in month depends on the previous two months’ growth, with a damping effect (the term ensures it doesn’t explode infinitely).
Visual: Repeated Root Solution Growth
Observation: The sequence grows exponentially but with a polynomial factor due to the repeated root. This mirrors how Khalti’s transaction volume grows rapidly but is constrained by regulatory limits (modeled by the term).
Based on the TU BIT syllabus for Discrete Structure (BIT152), unit 7.
Discussion
Loading…