1. Trang chủ
  2. » Giáo án - Bài giảng

Chapter 3 Sets and Functions Discrete Structures for Computer Science (CO1007)

89 536 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 89
Dung lượng 712,6 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Nguyen An Khuong, Huynh Tuong NguyenContents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion 4.1 Chapter 4 Sets and Functions Discrete Struct

Trang 1

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.1

Chapter 4

Sets and Functions

Discrete Structures for Computer Science (CO1007) on Ngày

Trang 2

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Contents

1 Sets

Trang 3

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.3

Set Definition

• Set is afundamentaldiscrete structure on which all discrete

structures are built

• Sets are used to group objects, which often have thesame

properties

Example

• Set of all the students who are currently taking Discrete

Mathematics 1 course

• Set of all the subjects that K2011 students have to take in

the first semester

• Set of natural numbers N

Definition

Asetis an unordered collection of objects

The objects in a set are called theelements(phần tử ) of the set

A set is said tocontain(chứa) its elements

Trang 4

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Notations

Definition

• a ∈ A: a is an element of the set A

• a /∈ A: a isnotan element of the set A

Definition (Set Description)

• The set V of all vowels in English alphabet, V = {a, e, i, o, u}

• Set of all real numbers greater than 1???

{x | x ∈ R, x > 1}

{x | x > 1}

{x : x > 1}

Trang 5

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 6

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Venn Diagram

• John Venn in 1881

• Universal set(tập vũ trụ) is

represented by a rectangle

• Circlesand other

geometrical figuresare used

to represent sets

• Pointsare used to represent

particular elements in set

Trang 7

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.7

Special Sets

• Empty set(tập rỗng ) has no elements, denoted by ∅, or {}

• A set with one element is called asingleton set

• What is {∅}?

• Answer: singleton

Trang 8

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Subset

Definition

The set A is called asubset(tập con) of B iff every element of A

is also an element of B, denoted by A ⊆ B

If A 6= B, we write A ⊂ B and say A is aproper subset(tập con

thực sự) of B

• ∀x(x ∈ A → x ∈ B)

• For every set S,

(i)∅ ⊆ S,(ii)S ⊆ S

Trang 9

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.9

Cardinality

Definition

If S has exactly n distinct elements where n is non-negative

integers, S isfinite set(tập hữu hạn), and n iscardinality(bản

số ) of S, denoted by |S|

Example

• A is the set of odd positive integers less than 10 |A| = 5

• S is the letters in Vietnamese alphabet, |S| = 29

Trang 10

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Power Set

Definition

Given a set S, thepower set(tập lũy thừa) of S is the set of all

subsets of the set S, denoted byP (S)

Example

What is the power set of {0, 1, 2}?

P ({0, 1, 2}) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}

Example

• What is the power set of the empty set?

• What is the power set of the set {∅}

Trang 11

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.11

Power Set

Theorem

If a set has n elements, then its power set has 2n elements

Prove using induction!

Trang 12

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Ordered n-tuples

Definition

Theordered n-tuple(dãy sắp thứ tự) (a1, a2, , an) is the

ordered collection that has a1 as its first element, a2 as its second

element, , and an as its nth element

Trang 13

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.13

Cartesian Product

• René Descartes (1596–1650)

Definition

Let A and B be sets TheCartesian product(tích Đề-các) of A

and B, denoted by A × B, is the set of ordered pairs (a, b), where

Trang 14

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 15

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 16

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 17

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 18

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 19

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 20

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 21

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 22

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Method of Proofs of Set Equations

To prove A = B, we could use

• Venn diagrams

• Prove that A ⊆ B and B ⊆ A

• Usemembership table

• Use set builder notation and logical equivalences

Trang 23

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 24

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 25

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 26

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 27

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.27

Introduction

• Each student is assigned a grade from set

{0, 0.1, 0.2, 0.3, , 9.9, 10.0} at the end of semester

• Function is extremely important in mathematics and

computer science

• linear, polynomial, exponential, logarithmic,

• Don’t worry! For discrete mathematics, we need to

understand functions at a basic set theoretic level

Trang 28

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Function

Definition

Let A and B be nonempty sets A functionf from A to B is an

assignment ofexactly oneelement of B to each element of A

• f : A → B

• For each a ∈ A, if f (a) = b

• b is animage(ảnh) of a

• a ispre-image(nghịch ảnh/tạo ảnh) of f (a)

• f maps (ánh xạ) A to B

f

Trang 29

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 30

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Example

Example

What are domain, codomain, and range of the function that

assigns grades to students includes: student A: 5, B: 3.5, C: 9, D:

5.2, E: 4.9?

Example

Let f : Z → Z assign the the square of an integer to this integer

What is f (x)? Domain, codomain, range of f ?

• f (x) = x2

• Domain: set of all integers

• Codomain: Set of all integers

• Range of f : {0, 1, 4, 9, }

Trang 31

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.31

Add and multiply real-valued functions

Definition

Let f1and f2 be functions from A to R Then f1+ f2 and f1f2

are also functions from A to R defined by

(f1+ f2)(x) = f1(x) + f2(x)(f1f2)(x) = f1(x)f2(x)

Trang 32

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 33

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

• Is f : Z → Z, f(x) = x2

one-to-one?

Trang 34

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

• Is f : Z → Z, f(x) = x2

onto?

Trang 35

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.35

One-to-one and onto (bijection)

Definition

f : A → B isbijective (one-to-one correspondence)(song ánh) if

and only if f isinjectiveandsurjective

• Let f be the function from{a, b, c, d} to {1, 2, 3, 4}

with f (a) = 4, f (b) = 2,

f (c) = 1, f (d) = 3 Is f abijection?

Trang 36

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Example

Trang 37

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

A one-to-one correspondence is callinvertible(khả nghịch)

because we can define the inverse of this function

Trang 38

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 39

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 40

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Function Composition

Definition

Given a pair of functions g : A → B and f : B → C Then the

f ◦ g : A → C

f ◦ g(a) = f (g(a))

Trang 41

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.41Example

Trang 42

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

(0, 0)(1, 1)(2, 4)(3, 9)

Definition

Trang 43

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

(3b) d−xe = −bxc(4a) bx + nc = bxc + n(4b) dx + ne = dxe + n

Trang 44

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 45

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Definition (Fibonacci Sequence)

Initial condition: f0= 0 and f1= 1

Trang 46

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Exercise (1)

Initial deposit: $10,000

Interest: 11%/year,compoundedannually (lãi suất kép)

After 30 years, how much do you have in your account?

Let Pn be the amount in the account after n years The sequence

{Pn} satisfies the recurrence relation

Pn= Pn−1+ 0.11Pn−1= (1.11)Pn−1

The initial condition is P0= 10, 000

Step 1 Solve the recurrence relation (iteration technique)

Trang 47

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

In this sequence, integer 1 appears once, the integer 2 appears

twice, the integer 3 appears three times, and so on Therefore

integer n appears n times in the sequence

We can prove that (try it!)

62

X

i=1

i = 1953

so the next 63 numbers (until 2016) is 63

Therefore, 2012th number in the sequence is 63

Trang 48

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

=Pn+1 k=1ark

=Pn k=0ark+ (arn+1− a)

= Sn+ (arn+1− a)

Trang 49

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.49

Recursion

Definition (Recurrence Relation)

An equation thatrecursively definesa sequence

Definition (Recursion (đệ quy))

The act of defining an object (usually a function) in terms of that

object itself

Trang 50

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Recursive Algorithms

Definition

An algorithm is calledrecursiveif it solves a problem by reducing

it to an instance of the same problem with smaller input

Trang 51

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

else if n = 1 then return 1

else return fibonacci (n-1) + fibonacci (n-2)

Trang 52

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Tower of Hanoi

There is a tower in Hanoi that has three pegs mounted on a board

together with64gold disks of different sizes

Initially, these disks are placed on the first peg in order of size,

with the largest on the borrom

The rules:

1 Move one at a time from one peg to another

2 A disk is never placed on top of a smaller disk

Goals: all the disks on the third peg in order of size

The myth says thatthe world will endwhen they finish the

puzzle

Trang 53

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 54

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Tower of Hanoi – 1 Disc

1

Trang 55

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 56

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Tower of Hanoi – 1 Disc

1

OK

Trang 57

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.57

Tower of Hanoi – 2 Discs

2

1

Trang 58

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Tower of Hanoi – 2 Discs

Moved disc from peg 1 to peg 2

Trang 59

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Trang 60

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

Tower of Hanoi – 2 Discs

21

Moved disc from peg 2 to peg 3

Trang 61

Nguyen An Khuong, Huynh Tuong Nguyen

Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion

4.61

Tower of Hanoi – 2 Discs

21

OK

Ngày đăng: 29/03/2017, 18:30

TỪ KHÓA LIÊN QUAN