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 PortalMATH2113Functions Recursive
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    MATH2113

    Discrete Mathematics

    Progress0 / 25 done
    Topics25
    1Sets, Subsets, Algebra of Sets2Propositions and Compound Statements3Basic Logical Operations4Propositional Logic and its Applications with Statement Problems5Propositions and Truth Tables6Tautologies and Contradictions7Conditional and Bi-conditional Statements8Arguments in Propositional Logic9Propositional Functions10Quantifiers and Negation of Quantified Statements11Relations and Equivalence Relations12Partial Ordering Relations13Functions and Recursively Defined Functions
    14Basics of Counting Methods15Combinations and Permutations16Pigeonhole Principle17Graphs and its Types18Graph Isomorphism19Trees in Graph Theory20Connectivity in Graphs21Eulerian and Hamiltonian Paths22Spanning Trees and Shortest Path Problem
    23Power, Floor, Increasing, Decreasing24Big O, Little O and Omega Notations25Orders of the Polynomial Functions
    11 min read
    Topic 13 of 25
    Topic Study Note Illustration
    13

    Functions and Recursively Defined Functions

    Functions and Recursively Defined Functions


    Functions and Recursively Defined Functions


    1. Functions

    A function is a relation between two sets that associates each element of one set (the domain) to exactly one element of another set (the codomain). A function is often denoted as:

    f:A→Bf: A \to Bf:A→B

    where AAA is the domain and BBB is the codomain. For each element a∈Aa \in Aa∈A, there exists exactly one element b∈Bb \in Bb∈B such that f(a)=bf(a) = bf(a)=b. The element bbb is called the image of aaa under the function fff.

    Components of a Function:

    1. Domain (A): The set of inputs or arguments.
    2. Codomain (B): The set of possible outputs.
    3. Rule (f): The rule that assigns each element from the domain to an element in the codomain.

    Example of a Function:

    Let f:R→Rf: \mathbb{R} \to \mathbb{R}f:R→R be the function defined by:

    f(x)=x2f(x) = x^2f(x)=x2

    This function maps each real number xxx to its square x2x^2x2.


    2. Types of Functions

    a) One-to-One (Injective) Function

    A function f:A→Bf: A \to Bf:A→B is one-to-one (or injective) if different elements in AAA map to different elements in BBB. That is, if f(a1)=f(a2)f(a_1) = f(a_2)f(a1​)=f(a2​), then a1=a2a_1 = a_2a1​=a2​.

    Example:
    The function f(x)=2xf(x) = 2xf(x)=2x, where f:R→Rf: \mathbb{R} \to \mathbb{R}f:R→R, is injective because if f(x1)=f(x2)f(x_1) = f(x_2)f(x1​)=f(x2​), then 2x1=2x22x_1 = 2x_22x1​=2x2​, which implies x1=x2x_1 = x_2x1​=x2​.


    b) Onto (Surjective) Function

    A function f:A→Bf: A \to Bf:A→B is onto (or surjective) if every element in BBB is the image of at least one element in AAA. In other words, for every b∈Bb \in Bb∈B, there is an a∈Aa \in Aa∈A such that f(a)=bf(a) = bf(a)=b.

    Example:
    The function f(x)=sin⁡(x)f(x) = \sin(x)f(x)=sin(x), where f:R→[−1,1]f: \mathbb{R} \to [-1, 1]f:R→[−1,1], is surjective because for every value y∈[−1,1]y \in [-1, 1]y∈[−1,1], there exists an x∈Rx \in \mathbb{R}x∈R such that f(x)=yf(x) = yf(x)=y.


    c) One-to-One Correspondence (Bijective) Function

    A function f:A→Bf: A \to Bf:A→B is bijective if it is both injective and surjective. This means every element of AAA maps to a unique element in BBB, and every element of BBB is the image of exactly one element from AAA.

    Example:
    The function f(x)=x+1f(x) = x + 1f(x)=x+1, where f:R→Rf: \mathbb{R} \to \mathbb{R}f:R→R, is bijective because it is both injective (no two different values map to the same output) and surjective (every real number is the image of some real number).


    3. Composition of Functions

    The composition of two functions f:A→Bf: A \to Bf:A→B and g:B→Cg: B \to Cg:B→C is a new function g∘f:A→Cg \circ f: A \to Cg∘f:A→C defined by:

    (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x))(g∘f)(x)=g(f(x))

    In other words, the output of f(x)f(x)f(x) is used as the input for ggg.

    Example:
    Let f(x)=x+1f(x) = x + 1f(x)=x+1 and g(x)=2xg(x) = 2xg(x)=2x, where f:R→Rf: \mathbb{R} \to \mathbb{R}f:R→R and g:R→Rg: \mathbb{R} \to \mathbb{R}g:R→R. The composition g∘fg \circ fg∘f is:

    (g∘f)(x)=g(f(x))=g(x+1)=2(x+1)=2x+2(g \circ f)(x) = g(f(x)) = g(x + 1) = 2(x + 1) = 2x + 2(g∘f)(x)=g(f(x))=g(x+1)=2(x+1)=2x+2

    4. Recursively Defined Functions

    A recursively defined function is a function that is defined in terms of itself. These functions typically have a base case that provides a specific value, and a recursive case that defines the function for other values in terms of the function applied to smaller or simpler inputs.

    Structure of a Recursive Function:

    1. Base Case: The simplest case(s) that do not use recursion.
    2. Recursive Case: The rule that defines the function for larger or more complex inputs, usually in terms of smaller inputs.

    5. Example of a Recursively Defined Function

    a) Factorial Function

    The factorial function, denoted n!n!n!, is defined recursively as follows:

    • Base Case: 0!=10! = 10!=1
    • Recursive Case: n!=n×(n−1)!n! = n \times (n-1)!n!=n×(n−1)! for n>0n > 0n>0

    So, we compute 5!5!5! as:

    5!=5×4×3×2×1=1205! = 5 \times 4 \times 3 \times 2 \times 1 = 1205!=5×4×3×2×1=120

    This function is defined by using the fact that n!n!n! depends on the value of (n−1)!(n-1)!(n−1)!.


    b) Fibonacci Sequence

    The Fibonacci sequence is another example of a recursively defined function, where each number is the sum of the two preceding ones:

    • Base Cases: F(0)=0F(0) = 0F(0)=0, F(1)=1F(1) = 1F(1)=1
    • Recursive Case: F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-2)F(n)=F(n−1)+F(n−2) for n≥2n \geq 2n≥2

    For example, the first few terms are:

    F(0)=0,F(1)=1,F(2)=F(1)+F(0)=1+0=1,F(3)=F(2)+F(1)=1+1=2,F(4)=F(3)+F(2)=2+1=3,…F(0) = 0, F(1) = 1, F(2) = F(1) + F(0) = 1 + 0 = 1, F(3) = F(2) + F(1) = 1 + 1 = 2, F(4) = F(3) + F(2) = 2 + 1 = 3, \dotsF(0)=0,F(1)=1,F(2)=F(1)+F(0)=1+0=1,F(3)=F(2)+F(1)=1+1=2,F(4)=F(3)+F(2)=2+1=3,…

    This recursive definition allows for the computation of any Fibonacci number by repeatedly applying the recurrence relation.


    6. Advantages and Disadvantages of Recursion

    Advantages:

    • Simplicity: Recursion can simplify the definition of functions that have a natural recursive structure (like factorial, Fibonacci).
    • Elegance: Many problems, especially those in mathematics, computer science, and algorithms, are elegantly solved using recursive functions.

    Disadvantages:

    • Efficiency: Recursive solutions can be less efficient than iterative solutions, especially for problems like Fibonacci, where overlapping subproblems lead to redundant calculations.
    • Stack Overflow: Deep recursion can lead to a stack overflow error, where the computer runs out of memory for storing function calls.

    7. Tail Recursion

    A recursive function is said to be tail-recursive if the recursive call is the last operation in the function. Tail recursion is more efficient because it allows the compiler to optimize the recursion (by reusing the same stack frame).

    Example: A tail-recursive version of the factorial function:

    factorial(n,acc)={accif n=0factorial(n−1,n×acc)if n>0\text{factorial}(n, acc) = \begin{cases} acc & \text{if } n = 0 \\ \text{factorial}(n-1, n \times acc) & \text{if } n > 0 \end{cases}factorial(n,acc)={accfactorial(n−1,n×acc)​if n=0if n>0​

    Where accaccacc is an accumulator that stores the result of the factorial computation as we go along.


    ← Previous topic 12
    Partial Ordering Relations
    Next topic 14 →
    Combinatorics: Basics of Counting Methods

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    11mremaining
    1.9kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Discrete Mathematics