Lecture_06_RelationsFunctions(2)
Lecture_06_RelationsFunctions(2)
CS 221
Level 4
Computer Science
Chapter 2
Sets
Sets, Venn Diagrams, Set Operations, cardinality and accountability.
Mathematical Reasoning
Chapter 5 Proof strategies, mathematical induction, recursive mathematical definitions, Structural
Induction.
Counting
Chapter 6 Basic rules, Pigeon hall principal, Permutations and combinations, Binomial coefficients
and Pascal triangle.
Graphs & Trees
Chapter 7 Graph terminology, Graph types, Connectivity, Graph coloring. Trees, Types of Trees,
Traversing trees. Introduction to Automata, DFA.
Functions
Definition: Let A and B be nonempty sets. A function
f from A to B, denoted f: A → B is an assignment
of each element of A to exactly one element of B.
We write f(a) = b if b is the unique element of B
assigned by the function f to the element a of A.
Students Grades
• Functions are sometimes Carlota
A
B
called mappings or Sandeep C
transformations. Williams D
F
Scott
Representing Functions
• Functions may be specified in different ways:
– An explicit statement of the assignment.
Students and grades example.
– A formula.
f(x) = x + 1
– A computer program.
• A Java program that when given an integer n, produces
the nth Fibonacci Number (covered in the next section
and also inChapter 5).
Questions
f(a) = ? z
A B
The image of d is ? z
a
x
The domain of f is ? A
b
y
The codomain of f is ? B
c
The preimage of y is ? b d z
f(A) = ? {y,z}
The preimage(s) of z is (are) ? {a,c,d}
A B
a
f {a,b,c,} is ? {y,z}
x
b
f {c,d} is ? {z} y
c
d z
Surjections
Definition: A function f from A to B is called
onto or surjective, if and only if for every
element there is an element
with . A function f is called a
surjection if it is onto. A B
a x
b
y
c
z
d
Bijections
Definition: A function f is a one-to-one
correspondence, or a bijection, if it is both
one-to-one and onto (surjective and injective).
A B
a x
b
y
c
d z
b
b W
W
c
c
d X
d X
Y
Y
and
Graphs of Functions
• Let f be a function from the set A to the set B. The
graph of the function f is the set of ordered pairs
{(a,b) | a ∈A and f(a) = b}.
Example:
f(6) = 6! = 1 ∙ 2 ∙ 3∙ 4∙ 5 ∙ 6 = 720
f(20) = 2,432,902,008,176,640,000.