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.
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 answerHide 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:
| Property | Definition |
|---|---|
| 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
| Term | Meaning |
|---|---|
| POSET | Set with a partial order relation |
| Comparable | $a \leq b$ or $b \leq a$ holds |
| Incomparable | Neither $a \leq b$ nor $b \leq a$ |
| Total Order | Every pair is comparable |
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 answerHide 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:
| Property | Condition |
|---|---|
| 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}$
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
$$\boxed{1010101010}$$
(b) Multiples of 5
$B = {0,5}$
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
$$\boxed{1000010000}$$
(c) Numbers greater than 7
$C = {8,9}$
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
$$\boxed{0000000011}$$
(d) Prime numbers
$D = {2,3,5,7}$ (1 is not prime)
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
$$\boxed{0011010100}$$
Summary
| Set | Elements | Bit 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$ |
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]
0 ยท 5 marks
Define celling and floor function. Explain Boolean function with example. [5]
One-to-one and onto functions
2080 ยท 5 marks
Explain one-to-one and onto function with example. What is identity function? [5]
One-to-one correspondence
2079 ยท 5 marks
Explain one-to-one correspondence with example. What is identity function? [5]
Function plotting
2080.1 ยท 5 marks
How do you plot graph for function $f(x) = x + 1$? Define ceiling, floor and exponential function. [5]
Make Unit 4 stick
Practice BIT152 with flashcards & quizzes