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
    🧩
    Discrete Structures
    GE-167
    Progress0 / 67 topics
    Topics
    1. Mathematical Reasoning: Propositional and Predicate Logic2. Propositional Logic: Logical Operators3. Translations Between Symbolic Expressions and Formal English Expression4. Logical Equivalences5. Predicate Logic: Quantifiers6. Nested Quantification7. Equivalences in Predicate Logic8. Translations Between Symbolic Forms and Formal English9. Rules of Inference: Proof Methods and Strategies10. Direct Proof11. Proof by Contraposition12. Proof by Induction13. Proof by Implication14. Existence Proof15. Uniqueness Proofs16. Trivial Proofs17. Vacuous Proofs18. Sets: Notations and Set Operations19. Venn Diagrams20. Countable and Uncountable Sets21. Relations: Equivalence Relations and Partitions22. Partial Orderings23. Recurrence Relations24. Functions: Injective, Surjective, Bijective25. Special Types of Functions26. Function Composition27. Inverse Functions28. Recursive Functions29. Compositions30. Number Theory: Sequences and Series31. Counting: Inclusion and Exclusion Principle32. Pigeonhole Principle33. Permutations and Combinations34. Integers and Divisibility: Division Theorem35. Modular Arithmetic36. LCM and GCD37. Euclidean and Extended Euclidean Method38. Finding Solutions to Congruence39. Primes: Fundamental Theorem of Arithmetic40. Characterizations of Primes41. Mersenne Primes42. Induction: Weak Induction43. Strong Induction44. Recursion and Recurrences: Formulation of Recurrences45. Closed Formulas46. Counting: Product Rule and Sum Rule47. Principle of Inclusion-Exclusion48. Binomial Coefficients49. Pascal's Identity and Pascal’s Triangle50. Binomial Theorem51. Relations: Reflexive, Symmetric, Transitive, and Antisymmetric52. Equivalence Relations and Equivalence Classes53. Partial Orders54. Graph Theory: Terminologies55. Elements of Graph Theory56. Planar Graphs57. Graph Coloring58. Euler Graph59. Hamiltonian Path60. Rooted Trees61. Graph Traversals62. Handshaking Lemma and Corollary63. Special Families of Graphs64. Graph Isomorphism65. Planarity in Graphs66. Eulerian and Hamiltonian Graphs67. Trees in Graph Theory
    GE-167›Recursion and Recurrences: Formulation of Recurrences
    Discrete StructuresTopic 44 of 67

    Recursion and Recurrences: Formulation of Recurrences

    9 minread
    1,600words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time9 min
      Word count1,600
      Code examples0
      DifficultyIntermediate