4 Functions And Mappings

Discrete Structure ยท Unit 4

Functions and Mappings

Exam-focused notes for Functions and Mappings (Discrete Structure, BIT152): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Functions and Mappings in short

A function matches each input with exactly one output. Functions are used everywhere in computing: in programs, in hashing, in digital circuits and in measuring how fast an algorithm grows.

Functions and Mappings: notes

Function definition and notation

Let $A$ and $B$ be non-empty sets. A function $f$ from $A$ to $B$, written $f: A \to B$, assigns to every element $a \in A$ exactly one element $f(a) \in B$.

  • $A$ is the domain, and $B$ is the codomain.
  • $f(a) = b$: $b$ is the image of $a$, and $a$ is a pre-image of $b$.
  • The range is the set of all images, ${f(a) \mid a \in A}$. It is a subset of the codomain.

Example. Let $A = {1, 2, 3}$, $B = {a, b, c, d}$ and $f(1) = a$, $f(2) = c$, $f(3) = c$. This is a function. The range is ${a, c}$. It is allowed for two inputs to share an output.

A rule is not a function if some input has two outputs, or some input has no output. For example, $x \mapsto \pm\sqrt{x}$ is not a function.

For $f: \mathbb{R} \to \mathbb{R}$, $f(x) = x^2$, the domain is $\mathbb{R}$ and the range is $[0, \infty)$.

One-to-one and onto functions

A function $f: A \to B$ is one-to-one (injective) if different inputs give different outputs:

$$f(a_1) = f(a_2) \implies a_1 = a_2$$

A function is onto (surjective) if every element of $B$ is the image of at least one element of $A$. That is, range equals codomain.

Example. $f: \mathbb{Z} \to \mathbb{Z}$, $f(x) = 2x + 1$.

  • One-to-one: if $2x_1 + 1 = 2x_2 + 1$ then $x_1 = x_2$. Yes.
  • Onto: is 2 an image? $2x + 1 = 2$ gives $x = 1/2$, which is not an integer. So it is not onto.

Example. $g: \mathbb{R} \to \mathbb{R}$, $g(x) = x^2$.

  • Not one-to-one, because $g(2) = g(-2) = 4$.
  • Not onto, because no real $x$ gives $-1$.

Example. $h: \mathbb{R} \to \mathbb{R}$, $h(x) = x^3$ is both one-to-one and onto.

To show a function is not one-to-one, give two inputs with the same output. To show it is not onto, give an element of the codomain with no pre-image.

What this unit covers

  • Function definition and notation
  • One-to-one and onto functions
  • Identity function
  • One-to-one correspondence
  • Boolean functions
  • Exponential functions
  • Ceiling and floor functions
  • Function plotting

Boolean functions

2082 ยท 5 marks

Define Boolean and exponential function. Discuss about partial ordering. [2+3]

Show solved answer

Boolean Function, Exponential Function, and Partial Ordering


1. Boolean Function (2 marks)

A Boolean function is a function of the form:

$$f: {0, 1}^n \rightarrow {0, 1}$$

It takes $n$ binary inputs (each either 0 or 1) and produces a single binary output (0 or 1). Boolean functions are expressed using Boolean operations: AND, OR, and NOT.

Example:

$$f(x, y) = x \cdot y + \bar{x}$$

where inputs $x, y \in {0, 1}$ and output $f \in {0, 1}$.


2. Exponential Function (3 marks, shared with partial ordering below)

An exponential function is a function of the form:

$$f(x) = a^x, \quad a > 0, ; a \neq 1$$

where $a$ is the base (a positive real constant) and $x$ is the exponent (variable).

Key properties:

  • Domain: all real numbers $\mathbb{R}$
  • Range: $(0, \infty)$
  • $f(0) = 1$ for any base $a$
  • If $a > 1$: function is increasing (growth)
  • If $0 < a < 1$: function is decreasing (decay)

Example: $f(x) = 2^x$ is an exponential growth function.


3. Partial Ordering

Definition

A partial order is a binary relation $R$ on a set $A$ that satisfies the following three properties:

PropertyDefinition
Reflexivity$\forall a \in A: (a, a) \in R$
Antisymmetry$\forall a, b \in A: (a,b) \in R \text{ and } (b,a) \in R \Rightarrow a = b$
Transitivity$\forall a, b, c \in A: (a,b) \in R \text{ and } (b,c) \in R \Rightarrow (a,c) \in R$

A set $A$ together with a partial order $R$ is called a partially ordered set (POSET), denoted $(A, R)$.

Note: In a partial order, it is not necessary that every pair of elements be comparable. If some elements cannot be compared, the order is called partial (as opposed to a total/linear order).


Example 1: Divisibility on Natural Numbers

Let $A = {1, 2, 3, 6}$ and $R$ = "divides" ($a \mid b$).

  • Reflexive: $1|1,; 2|2,; 3|3,; 6|6$ โœ“
  • Antisymmetric: If $a|b$ and $b|a$, then $a = b$ โœ“
  • Transitive: $1|2$ and $2|6 \Rightarrow 1|6$ โœ“

So $(A, |)$ is a POSET.


Example 2: Subset Relation

Let $A = \mathcal{P}({1,2}) = {\emptyset, {1}, {2}, {1,2}}$ and $R$ = "$\subseteq$".

  • Reflexive: Every set is a subset of itself โœ“
  • Antisymmetric: $X \subseteq Y$ and $Y \subseteq X \Rightarrow X = Y$ โœ“
  • Transitive: $X \subseteq Y$ and $Y \subseteq Z \Rightarrow X \subseteq Z$ โœ“

So $(\mathcal{P}({1,2}), \subseteq)$ is a POSET.


Hasse Diagram

A partial order can be represented visually using a Hasse diagram, where:

  • Elements are nodes
  • If $a < b$ and no element lies between them, draw $b$ above $a$ with a line connecting them
{1,2}
 /  \
{1} {2}
 \  /
  {}

This is the Hasse diagram for $(\mathcal{P}({1,2}), \subseteq)$.


Summary

TermMeaning
POSETSet with a partial order relation
Comparable$a \leq b$ or $b \leq a$ holds
IncomparableNeither $a \leq b$ nor $b \leq a$
Total OrderEvery pair is comparable
Open this answer on its own page โ†’

2081 ยท 10 marks

Define Boolean function, exponential function and partial ordering. List the computer representations for following set over universal set $U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}$: (a) Set that contains even number (b) Set that contains multiple of 5 (c) Set that contains number greater than 7 (d) Set that contains prime number. [6+4]

Show solved answer

Boolean Function, Exponential Function, Partial Ordering & Computer Representation of Sets


Given

  • Universal set: $U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}$ (10 elements)
  • Required definitions: Boolean function, exponential function, partial ordering.
  • Sets to represent as bit strings over $U$:
    • (a) even numbers
    • (b) multiples of 5
    • (c) numbers greater than 7
    • (d) prime numbers

Solution

(a) Definitions

Boolean Function

A Boolean function of $n$ variables is a function

$$f: {0,1}^n \rightarrow {0,1}$$

that assigns to each combination of $n$ Boolean inputs (0 or 1) a single output value in ${0,1}$. It is built from the operations AND ($\cdot$), OR ($+$), and complement ($\overline{\phantom{x}}$).

Example: $f(x,y,z) = x\cdot y + \overline{z}$.

Exponential Function

An exponential function has the form

$$f(x) = a^x, \quad a > 0,\ a \neq 1$$

where $a$ is the base and $x$ the exponent. Domain $=\mathbb{R}$, range $=(0,\infty)$.

Example: $f(x)=2^x$; occurs in complexity analysis such as $O(2^n)$.

Partial Ordering

A relation $R$ on a set $S$ is a partial ordering if it is:

PropertyCondition
Reflexive$\forall a \in S,\ (a,a)\in R$
Antisymmetric$(a,b)\in R \wedge (b,a)\in R \Rightarrow a=b$
Transitive$(a,b)\in R \wedge (b,c)\in R \Rightarrow (a,c)\in R$

The pair $(S,R)$ is a partially ordered set (poset).

Example: $\leq$ on $\mathbb{Z}$, and $\subseteq$ on a power set.


(b) Computer Representation of Sets

Convention: Order the elements of $U$ as $0,1,2,3,4,5,6,7,8,9$. Bit = 1 if the element is present, 0 otherwise.

$$\text{Positions: } 0\ 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9$$

(a) Even numbers

$A = {0,2,4,6,8}$

0123456789
1010101010

$$\boxed{1010101010}$$

(b) Multiples of 5

$B = {0,5}$

0123456789
1000010000

$$\boxed{1000010000}$$

(c) Numbers greater than 7

$C = {8,9}$

0123456789
0000000011

$$\boxed{0000000011}$$

(d) Prime numbers

$D = {2,3,5,7}$ (1 is not prime)

0123456789
0011010100

$$\boxed{0011010100}$$


Summary

SetElementsBit string
(a) Even${0,2,4,6,8}$$1010101010$
(b) Mult. of 5${0,5}$$1000010000$
(c) $>7$${8,9}$$0000000011$
(d) Prime${2,3,5,7}$$0011010100$
Open this answer on its own page โ†’

Ceiling and floor functions

2080 ยท 5 marks

State ceiling function and floor function with examples. How mathematical induction can be used to prove the correctness of recursive algorithm? Illustrate with an example.[5]

--- Definition: The floor function of a real number $x$, denoted $\lfloor x \rfloor$, is the greatest integer less than or equal to $x$. $$\lfloor x \rfloor = \max{n \in \mathbb{Z} \mid n \leq x}$$ Examples: - $\lfloor 4.7 \rfloor = 4$ - $\lfloor 3 \rfloor = 3$ - $\lfloor -2.3 \rfloor = -3$ ---...

Open this answer on its own page โ†’

0 ยท 5 marks

Define celling and floor function. Explain Boolean function with example. [5]

--- The floor function of a real number x, denoted โŒŠxโŒ‹, is defined as the greatest integer less than or equal to x. $$\lfloor x \rfloor = \text{largest integer } n \text{ such that } n \leq x$$ Examples: - โŒŠ3.7โŒ‹ = 3 - โŒŠ5โŒ‹ = 5 - โŒŠ-2.3โŒ‹ = -3 --- The ceiling function of a real number x, denoted โŒˆxโŒ‰,...

Open this answer on its own page โ†’

One-to-one and onto functions

2080 ยท 5 marks

Explain one-to-one and onto function with example. What is identity function? [5]

A function f: A โ†’ B is called one-to-one (injective) if every element of the domain maps to a distinct element in the codomain. Formal Definition: f is one-to-one if f(xโ‚) = f(xโ‚‚) implies xโ‚ = xโ‚‚, for all xโ‚, xโ‚‚ โˆˆ A. In other words, no two different inputs produce the same output. Example: Let f:...

Open this answer on its own page โ†’

One-to-one correspondence

2079 ยท 5 marks

Explain one-to-one correspondence with example. What is identity function? [5]

A function f: A โ†’ B is called a one-to-one correspondence (also called a bijection) if it is both one-to-one (injective) and onto (surjective). That means: - Injective: Every distinct element in A maps to a distinct element in B. - Formally: if f(xโ‚) = f(xโ‚‚), then xโ‚ = xโ‚‚ - Surjective: Every elem...

Open this answer on its own page โ†’

Function plotting

2080.1 ยท 5 marks

How do you plot graph for function $f(x) = x + 1$? Define ceiling, floor and exponential function. [5]

  • Function to plot: $f(x) = x + 1$ - Terms to define: ceiling function, floor function, exponential function --- This is a linear function of the form $f(x) = mx + c$ with slope $m = 1$ and y-intercept $c = 1$. Steps to plot: 1. Identify the form. Since it is linear, the graph is a straight line,...
Open this answer on its own page โ†’