Skip to main content
Discrete Math
CHAPTER 10 Beginner

Functions and Types of Functions

Updated: May 17, 2026
15 min read

# CHAPTER 10

Functions and Types of Functions

1. Introduction

In Chapter 9, we explored "Relations"—a wild, chaotic web where one element in Set A could randomly point to fifty different elements in Set B. In computer programming, that chaos is dangerous. When you pass a specific variable into a software method, you expect exactly *one* specific answer to be returned. You expect predictability. To achieve absolute predictability, mathematicians created Functions. A Function is simply a highly restricted, heavily disciplined Binary Relation. It is the mathematical blueprint for every single subroutine, method, and API call in software engineering.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define the strict mathematical rules separating a Function from a standard Relation.
  • Map the Domain, Codomain, and Range of an active Function.
  • Evaluate functions for Injective (One-to-One) compliance.
  • Evaluate functions for Surjective (Onto) compliance.
  • Master Bijective functions and their role in cryptographic inversion.

3. What is a Function?

A Function (let's call it $f$) is a mathematical machine that maps elements from an input set (Set A) to an output set (Set B) under one unbreakable, supreme law: The Golden Law of Functions: Every single input element in Set A MUST map to exactly ONE output element in Set B.
  • Notation: $f: A \rightarrow B$
  • Input/Output: If input $x$ produces output $y$, we write $f(x) = y$.

*The Vending Machine Analogy:* A function is a vending machine. If you press the "Coke" button ($x$), you must get exactly one Coke ($y$).

  • If you press "Coke" and the machine spits out a Coke *and* a Sprite... the machine is broken (It is a Relation, NOT a Function).
  • If you press "Coke" and nothing comes out... the machine is broken (NOT a Function).

4. Domain, Codomain, and Range

To architect a Function, we must explicitly define the spatial boundaries of the data.
  1. 1. Domain (The Inputs): The absolute set of all valid, legal inputs (Set A).
  1. 2. Codomain (The Potential Outputs): The overarching universe of all theoretically possible outputs (Set B).
  1. 3. Range (The Actual Outputs): The highly localized subset of Set B that was *actually hit* by an input.

*Example:* $f(x) = |x|$ (Absolute value). Domain = All Integers. Codomain = All Integers. But because absolute value deletes negatives, the engine can only physically output positive numbers! Therefore, the Range is restricted strictly to Positive Integers.

5. Injective Functions (One-to-One)

A function is Injective if no two different inputs ever generate the exact same output. Every output is uniquely claimed.
  • Rule: If $f(a) = f(b)$, then mathematically $a$ MUST equal $b$.
  • *Analogy:* Social Security Numbers. 500 million distinct humans (Inputs) map to 500 million distinct 9-digit codes (Outputs). No two humans share the same code.

6. Surjective Functions (Onto)

A function is Surjective if the machine successfully hits *every single item* in the Codomain. Nothing is left empty. The Range perfectly equals the Codomain.
  • Rule: For every $y \in B$, there exists at least one $x \in A$ such that $f(x) = y$.
  • *Analogy:* A hotel booking system. If there are 50 physical rooms (Codomain), and 50 distinct guests check-in (Inputs), every single room is actively occupied. The function is Surjective.

7. Bijective Functions (The Holy Grail)

If a function is incredibly precise and evaluates as BOTH Injective AND Surjective, it ascends to the highest architectural rank: a Bijection (or perfect One-to-One Correspondence). Every single input uniquely pairs with every single output, leaving absolutely zero gaps and zero duplicates.

The Power of Bijection (Inverse Functions): Only Bijective functions can be mathematically reversed! Because the mapping is perfectly 1-to-1, we can build an Inverse Function ($f^{-1}$) that drives the data backward from Set B to Set A. This is the foundational mathematics behind Data Encryption/Decryption. (Encrypt the data forward. Decrypt the data backward. Flawless Bijection).

8. Common Mistakes

  • Confusing a Function mapping two inputs to one output: If you press "Button 1" and get a Coke, and you press "Button 2" and get a Coke, is it a Function? YES! Each distinct button gave exactly one distinct answer. It is functionally valid (though it is NOT Injective). A Function only breaks if a single button yields *two* distinct answers!

9. Exercises

  1. 1. Determine if $f(x) = x^2$ is an Injective function assuming the Domain is all Real Numbers.
  1. 2. Why is it mathematically impossible to design an Inverse Decryption algorithm if the initial Encryption function is not Bijective?

10. MCQs with Answers

Question 1

What absolute, unbreakable mathematical constraint violently separates a highly disciplined "Function" from a chaotic baseline "Relation"?

Question 2

When defining the operational boundaries of a mathematical Function, what specific term designates the exact subset of outputs that were physically generated and "hit" by the inputs?

Question 3

If a cryptography architect mandates that a hashing algorithm must be completely collision-free (i.e., no two distinct passwords ever generate the identical hash output), what mathematical property are they enforcing?

Question 4

A video game engine maps 100 active player coordinates (Inputs) onto a 10,000-tile map grid (Codomain). Because 9,900 tiles remain completely empty, what formal architectural property does this Function fail?

Question 5

When a supreme mathematical Function miraculously satisfies both Injective and Surjective properties simultaneously, establishing perfect symmetric mapping, what is it classified as?

Question 6

What legendary computational "Superpower" is exclusively mathematically unlocked by Bijective Functions?

Question 7

If you evaluate the quadratic mathematical engine $f(x) = x^2$ operating across a Domain of all integers (including negative numbers), why does it fatally fail to achieve Injective (One-to-One) status?

Question 8

When a Junior Developer writes a Python method def calculate(n): return null what functional rule is broken?

Question 9

Is a standard Hash Function (used in Hash Maps to compress infinite string possibilities into a finite 10,000-slot integer array) fundamentally capable of being Injective?

Q10. True or False: In Discrete Mathematics, a Function is formally categorized as a specialized subset of a Binary Relation. a) True. A Function is quite literally just a localized Binary Relation extracted from a Cartesian Product that has been subjected to a secondary, hyper-restrictive logical filter demanding singular output paths. b) False. Functions and Relations are mathematically unrelated. Answer: a) True. A Function is quite literally just a localized Binary Relation extracted from a...

11. Interview Preparation

Top Interview Questions:
  • *System Design:* "You are designing the UUID generator for a massive global database. What mathematical property is the absolute most critical requirement for your generation function?" *(Answer: It MUST be Injective! If the function is not perfectly One-to-One, it will eventually generate a collision, assigning two distinct users the exact same UUID, irreparably corrupting the relational database matrix!)*

12. Summary

Functions are the disciplined, predictable engines of logic. By enforcing the strict rule of "One Input to One Output", computer scientists establish safe subroutine execution. Mastering the nuance of Injective, Surjective, and Bijective mappings is the mandatory prerequisite for architecting Cryptographic cyphers, Database Hash grids, and flawless System APIs.

13. Next Chapter Recommendation

We have mastered static logic, sets, and functions. But computer science is dynamic. We must execute loops, generate data over time, and evaluate infinite repeating patterns. In Chapter 11: Sequences and Summations, we will analyze the mathematical loops that power Array indexing and algorithmic Big O geometric counting matrices.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·