ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalGE-167Recursion Recurrences …
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    GE-167

    Discrete Structures

    Progress0 / 67 done
    Topics67
    1Propositional and Predicate Logic
    2Logical Operators3Translations Between Symbolic Expressions and Formal English Expression4Logical Equivalences
    5Quantifiers6Nested Quantification7Equivalences in Predicate Logic8Translations Between Symbolic Forms and Formal English
    9Proof Methods and Strategies10Direct Proof11Proof by Contraposition12Proof by Induction13Proof by Implication14Existence Proof15Uniqueness Proofs16Trivial Proofs17Vacuous Proofs
    18Notations and Set Operations19Venn Diagrams20Countable and Uncountable Sets
    21Equivalence Relations and Partitions22Partial Orderings23Recurrence Relations51Reflexive, Symmetric, Transitive, and Antisymmetric52Equivalence Relations and Equivalence Classes53Partial Orders
    24Injective, Surjective, Bijective25Special Types of Functions26Function Composition27Inverse Functions28Recursive Functions29Compositions
    30Sequences and Series
    31Inclusion and Exclusion Principle32Pigeonhole Principle33Permutations and Combinations46Product Rule and Sum Rule47Principle of Inclusion-Exclusion48Binomial Coefficients49Pascal's Identity and Pascal’s Triangle50Binomial Theorem
    34Division Theorem35Modular Arithmetic36LCM and GCD37Euclidean and Extended Euclidean Method38Finding Solutions to Congruence
    39Fundamental Theorem of Arithmetic40Characterizations of Primes41Mersenne Primes
    42Weak Induction43Strong Induction
    44Formulation of Recurrences45Closed Formulas
    54Terminologies55Elements of Graph Theory56Planar Graphs57Graph Coloring58Euler Graph59Hamiltonian Path60Rooted Trees61Graph Traversals62Handshaking Lemma and Corollary63Special Families of Graphs64Graph Isomorphism65Planarity in Graphs66Eulerian and Hamiltonian Graphs67Trees in Graph Theory
    9 min read
    Topic 44 of 67
    Topic Study Note Illustration
    44

    Recursion and Recurrences: Formulation of Recurrences

    In mathematics and computer science, recursion refers to the process where a function calls itself in its definition. It is a method used to solve problems by...

    Recursion and Recurrences: Formulation of Recurrences

    Recursion

    In mathematics and computer science, recursion refers to the process where a function calls itself in its definition. It is a method used to solve problems by breaking them down into smaller, similar subproblems. Recursive problems typically have a "base case," which provides a simple, non-recursive solution for the smallest instances of the problem, and a recursive case, which solves the problem by reducing it to smaller subproblems.

    A recursive function typically follows the structure:

    1. Base Case(s): Defines the solution for the smallest or simplest input(s), usually without recursion.
    2. Recursive Case: Defines the solution for a larger problem in terms of smaller instances of the same problem.

    Example of Recursion: Factorial Function

    The factorial function n!n!n! is defined as the product of all positive integers less than or equal to nnn. Using recursion, the factorial can be defined as:

    n!={1if n=0n×(n−1)!if n>0n! = \begin{cases} 1 & \text{if } n = 0 \\ n \times (n-1)! & \text{if } n > 0 \end{cases}n!={1n×(n−1)!​if n=0if n>0​

    Here:

    • Base Case: 0!=10! = 10!=1 (since 0 factorial is defined as 1).
    • Recursive Case: n!=n×(n−1)!n! = n \times (n-1)!n!=n×(n−1)!.

    Recurrences

    A recurrence relation (or simply recurrence) is an equation that defines a sequence of values in terms of previous terms in the sequence. Recurrences are commonly used in computer science to model the running time of recursive algorithms, particularly divide-and-conquer algorithms.

    Formulation of Recurrences

    Formulating a recurrence involves expressing the problem in a recursive way, based on the structure of the problem. When formulating recurrences, you identify:

    1. The base case(s): The simplest problem(s) where the solution is known directly.
    2. The recursive case(s): A way to break down the problem into smaller subproblems, along with a recurrence relation that defines how the solution for a larger problem can be obtained from smaller subproblems.

    Example of Recurrence Formulation: Merge Sort

    Let's consider the Merge Sort algorithm, a classic divide-and-conquer algorithm used to sort an array. The idea behind Merge Sort is to:

    1. Divide the array into two halves.
    2. Recursively sort each half.
    3. Merge the sorted halves to produce the final sorted array.

    To analyze the running time of Merge Sort, we can formulate a recurrence relation. Let T(n)T(n)T(n) represent the time complexity of Merge Sort for an array of size nnn.

    • Base case: If the array has only one element (or is empty), no sorting is needed, so the time complexity is constant. Thus, T(1)=O(1)T(1) = O(1)T(1)=O(1).

    • Recursive case: To sort an array of size nnn, Merge Sort divides the array into two subarrays of size n/2n/2n/2, recursively sorts each subarray, and then merges the two sorted subarrays. The merging step takes O(n)O(n)O(n) time. Therefore, the recurrence relation for T(n)T(n)T(n) is:

    T(n)=2T(n2)+O(n)T(n) = 2T\left(\frac{n}{2}\right) + O(n)T(n)=2T(2n​)+O(n)

    Here:

    • 2T(n2)2T\left(\frac{n}{2}\right)2T(2n​) accounts for the recursive sorting of the two subarrays.
    • O(n)O(n)O(n) accounts for the merging step.

    This recurrence helps describe the time complexity of Merge Sort, which can be solved using methods such as the recursion-tree method or the Master Theorem.

    Steps for Formulating Recurrences

    When you are tasked with formulating a recurrence relation for a recursive algorithm or problem, follow these general steps:

    1. Identify the base case(s): This is the simplest form of the problem that can be solved directly without recursion. It typically involves small input sizes or trivial computations.

    2. Define the recursive case(s): Determine how the problem can be broken down into smaller subproblems. This usually involves dividing the input into smaller pieces and solving each piece recursively. If the input size is nnn, break it down into subproblems of smaller sizes, such as n/2n/2n/2, n/3n/3n/3, etc.

    3. Express the time complexity or solution for the problem in terms of the time complexity or solution of the subproblems. Typically, this results in a recurrence relation that expresses the total work as a function of the work done on the subproblems and any additional work done outside of the recursion (e.g., merging, computing results).

    Example 2: Fibonacci Numbers

    The Fibonacci sequence is another classic example of a recursive problem. The Fibonacci numbers F(n)F(n)F(n) are defined as:

    F(n)={0if n=01if n=1F(n−1)+F(n−2)if n>1F(n) = \begin{cases} 0 & \text{if } n = 0 \\ 1 & \text{if } n = 1 \\ F(n-1) + F(n-2) & \text{if } n > 1 \end{cases}F(n)=⎩⎨⎧​01F(n−1)+F(n−2)​if n=0if n=1if n>1​

    This is a direct recursive definition, but if we were to express the time complexity of a naive recursive approach to calculate Fibonacci numbers, the recurrence relation would be:

    T(n)=T(n−1)+T(n−2)+O(1)T(n) = T(n-1) + T(n-2) + O(1)T(n)=T(n−1)+T(n−2)+O(1)

    Here:

    • T(n−1)T(n-1)T(n−1) and T(n−2)T(n-2)T(n−2) represent the recursive calls to calculate F(n−1)F(n-1)F(n−1) and F(n−2)F(n-2)F(n−2), respectively.
    • O(1)O(1)O(1) represents the constant time required to add the two values F(n−1)F(n-1)F(n−1) and F(n−2)F(n-2)F(n−2).

    Solving Recurrences

    Once a recurrence relation is formulated, the next step is solving it to determine the time complexity or behavior of the algorithm. Common techniques to solve recurrences include:

    1. Substitution Method: This method involves guessing the solution and using induction to prove it.
    2. Recursion Tree: This method visualizes the recurrence as a tree, where each node represents a subproblem, and the branches represent recursive calls.
    3. Master Theorem: This provides a straightforward way to solve recurrences of a specific form, commonly used for divide-and-conquer algorithms.

    Master Theorem for Divide-and-Conquer Recurrences

    The Master Theorem is a powerful tool for solving recurrences of the form:

    T(n)=aT(nb)+O(nd)T(n) = aT\left(\frac{n}{b}\right) + O(n^d)T(n)=aT(bn​)+O(nd)

    Where a≥1a \geq 1a≥1, b>1b > 1b>1, and d≥0d \geq 0d≥0. The Master Theorem provides solutions based on the values of aaa, bbb, and ddd.

    • Case 1: If a>bda > b^da>bd, then T(n)=O(nlog⁡ba)T(n) = O(n^{\log_b a})T(n)=O(nlogb​a).
    • Case 2: If a=bda = b^da=bd, then T(n)=O(ndlog⁡n)T(n) = O(n^d \log n)T(n)=O(ndlogn).
    • Case 3: If a<bda < b^da<bd, then T(n)=O(nd)T(n) = O(n^d)T(n)=O(nd).

    Using this theorem, you can quickly determine the time complexity for many divide-and-conquer recurrences.

    Conclusion

    Formulating recurrences is essential for analyzing recursive algorithms and solving problems with a recursive structure. By expressing the problem in terms of smaller subproblems and combining the results of these subproblems, recurrences help characterize the behavior of algorithms and solutions. Understanding how to correctly formulate and solve recurrences is a critical skill in both mathematics and computer science.

    ← Previous topic 43
    Strong Induction
    Next topic 45 →
    Closed Formulas

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    9mremaining
    1.6kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Discrete Structures