ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Math Deficiency – II
    MD-002
    Progress0 / 32 topics
    Topics
    1. Complex Numbers2. Arithmetic with Complex Numbers (Add, subtract, multiply and divide complex numbers)3. Trigonometric Polar Form of Complex Numbers4. De Moivre's Theorem and nth Roots5. Recursion6. Sequences and Series7. Sigma Notation8. Arithmetic Series9. Geometric Series (Sum infinite and finite geometric series and categorize geometric series)10. Counting with Permutations and Combinations11. Basic Probability12. Binomial Theorem13. Limit: Notation, Graphs to Find Limits, Tables to Find Limits14. Substitution to Find Limits, Rationalization to Find Limits15. One Sided Limits and Continuity16. Rate of Change: Instantaneous Rate of Change17. Tangent Lines and Rates of Change18. Derivatives: The Derivative Function19. Introduction to Techniques of Differentiation20. The Product and Quotient Rules21. Derivatives of Trigonometric Functions22. The Chain Rule23. Derivatives of Logarithmic Functions24. Derivatives of Exponential and Inverse Trigonometric Functions25. Increase, Decrease, and Concavity26. Relative Extrema, Absolute Maxima and Minima27. Integrals: An Overview of the Area Problem28. Area Under a Curve29. The Indefinite Integral30. Integration by Substitution31. The Definition of Area as a Limit; Sigma Notation32. The Definite Integral
    MD-002›Recursion
    Math Deficiency – IITopic 5 of 32

    Recursion

    4 minread
    762words
    Beginnerlevel

    Recursion in Mathematics and Computer Science

    1. Definition and Basic Concept

    Recursion is a process where a function or algorithm calls itself directly or indirectly to solve a problem by breaking it into smaller, self-similar subproblems.

    • Base Case: The simplest instance of the problem, which can be solved directly without further recursion.
    • Recursive Case: The step where the function calls itself with a modified input, progressing toward the base case.

    Example (Factorial Function):
    n!=n×(n−1)!n! = n \times (n-1)!n!=n×(n−1)!
    with base case 0!=10! = 10!=1.


    2. Mathematical Recursion vs. Programming Recursion

    • Mathematical Recursion:

      • Defined using recurrence relations (e.g., Fibonacci sequence: F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-2)F(n)=F(n−1)+F(n−2)).
      • Used in sequences, series, and combinatorial problems.
    • Programming Recursion:

      • Functions call themselves (e.g., recursive factorial in Python):
        def factorial(n):
            if n == 0:  # Base case
                return 1
            else:       # Recursive case
                return n * factorial(n - 1)
        
      • Requires termination conditions to avoid infinite loops.

    3. Types of Recursion

    1. Direct Recursion:

      • A function calls itself directly.
      • Example: Factorial, Fibonacci.
    2. Indirect Recursion:

      • Function A calls function B, which calls A again.
      • Example:
        def is_even(n):
            if n == 0: return True
            else: return is_odd(n - 1)
        def is_odd(n):
            if n == 0: return False
            else: return is_even(n - 1)
        
    3. Tail Recursion:

      • The recursive call is the last operation in the function.
      • Can be optimized into iteration (avoiding stack overflow).
      • Example:
        def factorial(n, accumulator=1):
            if n == 0: return accumulator
            else: return factorial(n - 1, n * accumulator)
        
    4. Tree Recursion:

      • Multiple recursive calls per step (e.g., Fibonacci without memoization).
      • Inefficient without optimization (exponential time complexity).

    4. Solving Recurrence Relations

    A recurrence relation defines a sequence recursively (e.g., T(n)=2T(n/2)+nT(n) = 2T(n/2) + nT(n)=2T(n/2)+n).

    • Methods:
      • Substitution: Guess a solution and verify by induction.
      • Master Theorem: Solves divide-and-conquer recurrences of form T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n)T(n)=aT(n/b)+f(n).
      • Generating Functions: Encode sequences as power series to find closed-form solutions.

    Example (Merge Sort Recurrence):
    T(n)=2T(n2)+O(n)T(n) = 2T\left(\frac{n}{2}\right) + O(n)T(n)=2T(2n​)+O(n)
    Solution: T(n)=O(nlog⁡n)T(n) = O(n \log n)T(n)=O(nlogn) (Master Theorem Case 2).


    5. Applications of Recursion

    • Algorithms:
      • Divide-and-conquer (QuickSort, MergeSort).
      • Backtracking (solving puzzles like N-Queens).
    • Data Structures:
      • Tree traversals (in-order, pre-order).
      • Graph algorithms (DFS).
    • Mathematics:
      • Fractals (Mandelbrot set).
      • Dynamic programming (solving combinatorial problems).

    6. Advantages and Pitfalls

    • Advantages:
      • Simplifies code for problems with inherent recursive structure.
      • Natural fit for problems with hierarchical or nested patterns.
    • Pitfalls:
      • Stack overflow for deep recursion (unless tail-recursion optimized).
      • Redundant calculations (e.g., naive Fibonacci recursion recalculates values).
      • Solution: Memoization (caching results of expensive calls).

    7. Recursion vs. Iteration

    • Recursion:
      • Elegant for problems with self-similarity.
      • Higher memory usage (call stack).
    • Iteration:
      • Uses loops (e.g., for, while).
      • Generally more memory-efficient.
    • Convertibility:
      • All recursive algorithms can be rewritten iteratively (using stacks).
      • Tail recursion is trivially convertible to iteration.

    Example (Fibonacci Iterative vs. Recursive):

    # Recursive (O(2^n) time)
    def fib(n):
        if n <= 1: return n
        else: return fib(n-1) + fib(n-2)
    
    # Iterative (O(n) time)
    def fib_iter(n):
        a, b = 0, 1
        for _ in range(n):
            a, b = b, a + b
        return a
    

    8. Conclusion

    Recursion is a fundamental concept bridging mathematics and computer science, enabling elegant solutions to problems with repetitive substructures. Mastery requires understanding base cases, termination, and optimization techniques (e.g., memoization, tail recursion). While powerful, it must be used judiciously to avoid inefficiency or stack overflows.

    Previous topic 4
    De Moivre's Theorem and nth Roots
    Next topic 6
    Sequences and Series

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time4 min
      Word count762
      Code examples0
      DifficultyBeginner