Introduction to Discrete Mathematics Ch3
Transcript of Introduction to Discrete Mathematics Ch3
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 1/28
Chapter 3The Fundamentals: Algorithms, the integers, and matrices
Section3.1: Algorithms
Definition1: an algorithm is a finite set of precise instructions for performing acomputation or for solving a problem.
Example1: page168: describe an algorithm for finding the maximum value in a finitesequence of integers. Answer: we can specify a procedure for solving this problem in several ways. One
method is simply to use the English language to describe the sequence of steps used.1- Set the temporary maximum equal to first integer in the sequence2- Compare the next integer in the sequence to the temporary maximum, if it is larger than the temporary max., set the temporary maximum equal to this integer.3- Repeat the previous step if there are more integers in the sequence.4- Stop when there are no integers left in the sequence. The temporary maximum at this
point is the largest integer in the sequence.
Remark: 1- An algorithm can also be described using a computer language.2- Pseudo code: provides an intermediate step between an English language
description of an algorithm and an implementation of this algorithm in a programminglanguage.
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 2/28
3- The pseudo code used in this book is loosely used on programming language Pascal.4- A pseudo code description of the algorithm for finding the maximum element in a finite
sequence follows:
Read searching Algorithms-sorting (The bubble sort- The intersection sort- Greedy Algorithms).
_ aelement est l theis
athenaif
ntoi for
a
egersaaa procedure
ii
n
argmax
:maxmax
2:
:max
int:,........,max
1
21
!
!
!
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 3/28
Section 3.4: The integers and divisionNumber theory: the part of mathematics involving integers and their properties belongs
to the branch of mathematics called number theory.Definition: if a and b are integers with a�0 we say that a divides b if there is an integer c
such that b = ac. (Note that a is a factor of b)Remark: 1- We denote a divides b by ab
2- We denote a doesn¶t divide b by a »bExample1: determine whether 37 and whether 312answer: 3 does not divide 7 and 312 since 12 = 3.4
Example2: let n and d be positive integers. How many positive integers not exceeding nare divisible by d? Answer: The positive integers divisible by d is of the form kd. So kd is not exceeding n.
So . Therefore there are n/d positive integers not exceedingn that are divisible by d. k
nd nd k ee 00
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 4/28
Theorem 1:Let a,b and c be integers. Theni) If ab and ac, then a(b+c)ii) If ab then abc for all integers c;
iii) If ab and bc, then ac
Proof:
ca so
a Lk c
ka Lclbcthencb If kabthenba If iii
cba
ceger kaccb
kabthenba If ii
cbaak k ak ak cbnow
ak cthenca y
ak bthenba If i
/
)(
)(//)
/
int)(
/)
/
/
/)
2121
2
1
!
!!
!
!
!
!!
!
!
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 5/28
Corollary: If a,b, and c are integers such that ab and a/c, then a mb+nc whenever mand n are integers.
Proof: Since ab by theorem(1) ii ambSince ac by theorem (1) ii anc
So by theorem (1) I amb+nc
Theorem 2: The Division AlgorithmLet a, b, and c are integers and d a positive integer. Then there are unique q and r, with
o � r < d, such that a = dq + r.
Example: let a = 17d = 3 then 17 = 3.5 + 2
Definition: In the theorem 2, d is called the divisor, a is called the dividend, q is called the
quotient, and r is called the remainder.q = a div d, r = a mod d.
Example3: what are q and r when 101 is divided by 11?Solution: 101 = 9(11)+2
q = 9 , r =2So 9 = 101 div 11 2 = 101 mod 11
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 6/28
Example4: what are the quotient and remainder when -11 is divided by 3? Answer: -11 = 3(-4) + 1so -4= -11 div 3
1 = -11 mod 3
Note that r can¶t be negative. 0 � r < 3
Remark: the integer a is divisible by the integer d if and only if the remainder is zero.
Modular Arithmetic:
Definition3: If a and b are integers and m is a positive integer, then a is congruent to bmodulo m if m divides a-b. We use notation a b (mod m) to indicate that acongruent to b modulo m.
Theorem3: let a and b be integers, and let m be a positive integer. Then a b (mod m)
if and only if a mod m = b mod m.Ex5: 1- determine whether 17 is congruent to 5 modulo 62- Determine whether 24 is congruent to 14 modulo 6
Solution: 17 ± 5 = 12, 612 so 17 5 (mod 6)24 ± 14 = 10, 6»10 so 24 is not congruent to 14 (mod 6)
|
|
|
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 7/28
Theorem4: let m be a positive integer. The integers a and b are congruent modulo m iff there is an integer k such that a = b + km
Proof: suppose a b mod (m) m / a-b a-b=km
a=b+kmConversely: suppose a = b + km k is an integer
a ± b = km m / a ± b ( definition of divisibility) a b ( mod m)
Theorem5: let m be a positive integer. If a b (mod m) and c d (mod m), thena + c b + d (mod m) and ac bd (mod m).Proof: since a b (mod m) m / a ± b a = b + mSince c d (mod m) m / c- d c = d + ma + c = (b + d) + m (a + c) ± (b + d) =
m / (a + c) ± (b + d) a + c b + d mod (m)a . c =
|
|
| || |
| 1k
| 2k 21 k k 21 k k
|
)(
)(
2112
2
211221
mk k d k bk mbd
mk k md k mbk bd mk d mk b
!
!
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 8/28
Example6: 1- Show that 18 3 (mod 5), by using theorem 5:Solution: 18 = 7 + 11, 3 = 2 + 1 7 2 mod (5)
11 1 mod (5)18 = 7 + 11 2 + 1 = 3 (mod 5)
so 18 3 (mod 5)2- Show that 77 2 (mod 5) by using theorem 577 = (7)(11) (2)(1) (mod 5)77 2 (mod 5)
Corollary 2: let m be a positive integer and let a and b be integers. Then(a + b) mod m = ((a mod m) + (b mod m)) mod m And ab (a mod m) (b mod m) (mod m)
Application of Congruences
Read example7. Hashing FunctionsRead example8Remark on example8:1- Pseudorandom Numbers: numbers generated by systematic methods are not truly
random, they are called Pseudorandom Numbers.
|||
|| ||
|
|
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 9/28
2- we generate a sequence of pseudorandom numbers with for all nby using the congruence
Cryptology: is the study of secret messages.Caesar encryption: is the process of making a message secret by shifting each letter
forward. Eg. B sends to E, X sends to FCaesar¶s encryption method can be represented by the function f that assigns to the
nonnegative integer p, p � 25, the integer f(p) is the set {0,1,««,25} withf(p) = (p+3) mod 26 note that in this process we replace each letter by an integer from 0to 25, based on it¶s position for example replace A by 0, K by 10 and so on.
Example9: what is the secret message produced from the message ³Meet you in thepark´ using the Caesar Cipher?
Solution: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251) Replace the letters in the message with numbers
M e e t y o u I n t h e p a r k12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10
_ an x m xn e0
m xand mcma
with seed xmca x x nn
eee
!
0
01
00,2
,mod)(
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 10/28
2) Replace each of these numbers ply f(p)=(p+3)mod 2615 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13
3) Translating this back to letters produces encrypted message
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13P H H W B R X L Q W K H S D U N
Decryption: the process of determining the original message from the encryptedmessage is call decryption
Remark: instead of shifting each letter by 3, we can shift each letter by k so thatf(p)=(p+k) mod26 (called shift cipher)
Example: Decrypt the message using the Caesar Cipher:E O X H M H D C V
4 14 23 7 12 7 3 16 21
1 11 20 4 9 4 0 13 18 ( f(p)=p-3 )
B L U E J E A N S
Do example10 page 208
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 11/28
Using f(p)=(p+3)(mod26)Decrypt the message
G R Q R W S D V V
6 17 16 17 22 18 3 21 213 14 13 14 19 15 0 18 18³D O N O T P A S S´
Encrypt the message ³ how are you´
H O W A R E Y O U7 14 22 0 17 4 24 14 2010 17 25 3 20 7 1 17 23K R Z D M H B R X
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 12/28
Section 3.5Primes and Greatest Common Divisors
A prime: is an integer greater than 1 that is divisible only by 1 and by itself.Definition: a positive integer p greater than 1 is called prime if the only positive factors of
p are 1 and p.
Remark: 1- A positive integer that is greater than 1 and is not prime called composite.2- The integer n is composite iff there exists an integer a such that an and 1 < a < n.
Examples of prime numbers:2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89 and 97
Theorem1: the fundamental theorem of Arithmetic. Every positive integer greater than 1Can be written uniquely as a prime or as the product of two or more primes where the
Prime factors are written in order of non decreasing size.
Example2: Find the prime factorization of 100,641,999, and 1024.Solution: 100 = 2.2.5.5
= 2².5²
641 = 641 X 1 (prime)
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 13/28
999 = 3³ . 37
1024 = 2
Theorem2: If n composite integer, then n has a prime divisor less than or equal to
Example: Show that 101 is primeSolution: The only prime not exceeding ¥101 are 2,3,5 and 7. But ¥101 is not divisible by
2,3,5, or 7 it follows that 101 is prime.
Example4: Find the prime factorization of 7007.Solution: start with 2 then 3 then 5 . None of them divides 7007Try 7, we get 7007 = 7² X 11 X 13
Theorem3: There are infinitely many primesMersenne primes: The largest prime known has been an integer of special form 2 ± 1
10
p
n
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 14/28
Example5: page 212
Theorem4: The prime number theorem. The ratio of the number of primes are notexceeding x and x / lnx approaches 1 as x grows without bound.
Conjectures and open problems about primes.1- Consider the polynomial f(n) = n² - n + 41. This polynomial has the property that f(n) is
prime for all positive integers not exceeding 40.Eg: f(1) = 41 f(3) = 47 f(2) = 43 f(4) = 53 and so on.2- Every odd integer n, n > 5 is the sum of 3 primes
Every even integer n, n > 2 is the sum of 2 primesEg: 4 = 2 + 2, 6 = 3 + 3, 8 + 5 + 3, 10 = 7 + 3 and so on3- There are infinitely many primes of the form n² + 1 where n is a positive integer.Eg: 5 = 2² + 1, 17 = 4² + 1, 37 = 6² + 1 and so on4- The twin prime conjecture: Twin primes are primes that differ by 2 such as 3 and 5, 5
and 7, 11 and 13, 17 and 19.P + 2 where p is prime and p + 2 is prime or the product of two primes .
89.232047204712
3112
712
312
11
5
3
2
!!
±À
±¿
¾
!
!
!
because prime Mersenneanot ishile
primes MersennearenumbersThe
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 15/28
Greatest Common Divisors and Least Common MultiplesDefinition2: let a and b be integers, not both zero. The largest integer d such that da
and db is called the greatest common divisor of a and b denoted by gcd (a,b).Remark: One way to find the greatest common divisor of two integers is to find all the
positive common divisors of both integers and then take the largest divisior.Example10 page 215What is the greatest common divisor of 24 and 36 ?Solution: 24:1,2,3,4,6,8,12,24 (factors of 24)
36: 1,2,3,4,6,9,12,16,36 (factors of 36)
g.c.d(24,36) = 12Example11: Find g.c.d (17,22)Solution: 17: 1, 17
22: 1, 2,11,22g.c.d (17, 22) = 1
Definition3: The integers a and b are relatively prime if their greatest common divisor is1.Example12: Since g.c.d (17,22) = 1 it follows that the integers 17 and 22 are relativelyprime.
Definition4:
n jiwhenever aaif
primerel ativel y pairwiseareaaaegershe
ji
n
ee! 11),(gcd
,.......,,int 21
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 16/28
Example13: Determine whether the following integers are pair wise relatively prime1- 10, 17, 212- 10, 19, and 24Solution: 1- g.c.d(10,17)=1
g.c.d(17,21)=1g.c.d(10,21)=1
We calculate that 10,17,21 are pair wise relatively prime.2- g.c.d(10,19)=1
g.c.d(19,24)=1
g.c.d(10,24)=2>1So 10,19 and 24 are not pair wise relatively prime.
Remark: Another way to find the prime g.c.d if 2 integers is to use the primefactorizations of these integers suppose
),min(),min(
1
21
21
.........),(..
.................
11
21
21
nn
n
n
ba
n
ba
b
n
bb
a
n
aa
p pbad c g
p p pb p p pa
!
!!
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 17/28
Example14: find the g.c.d (120,500) (using method 2, prime factorization)
120 = 2³.3.5
} g.c.d(120,500)= 2².5= 20
500 = 2².5³
10 10
5 2 5 2
least common multipleDefinition5: The least common multiple of the positive integers a and b is the smallestPositive integer that is divisible by both a and b it is denoted by Lcm(a,b)Remark: lcm(a,b) =
120
12 10
3 2 2 2 5
500
5 100
),max(),max(
2
),max(
1 .......... 2211 nn ba
n
baba p p p
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 18/28
Example: What is the least common multiple of Answer:
Theorem5: let a and b be positive integers then ab = gcd (a,b) . Lcm (a,b)
?32732 34253 and
254
)0,2max()3,5max()4,3max(34253
7.3.2
7.3.232,732
!
! Lcm
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 19/28
Section 3.6: Integers and Algorithms
Representations of Integers:Theorem(1): (The base b expansion of n).
Let b be a positive integer greater than1. Then if n is a positive integer, it can beexpressed uniquely in the form
Where k is a non negative integer, are non negative integers less thanb and
Example: 965 = 9 X 10² + 6 X 10 + 5 X 10Û the base here is 10Remark: (1) In theorem 1: The base b expansion of n is denoted byExample: (245) represents 2.8²+4.8+5=165 the base here is 8
(2) Choosing 2 as the base gives binary expansions of integers.(3) In binary notation each digit is either a0 or a1. So the binary expansions of
an integer is just a bit string.
Example1: What is the decimal expansion of the integer that has (101011111) as itsbinary expansion?Solution:
01
1
1 ...... abababan k
k
k
k !
k aaa ,,........., 100{k a
bk k aaaa 011....
8
2
351212121
21212.12.02.12.02.1)101011111(
012
3345678
2
!
!
X X X
X X
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 20/28
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 21/28
This process terminates when we obtain a quotient equal to zeroExample3 page 220: Find the base 8, or octal, expansion of (12345)Solution: Divide 12345 by 8 12345 = 8.1543 + 1
Divide 1543 by 8 1543 = 8.192 + 7
192 = 8.24 + 024 = 8.3 + 03 = 8.0 + 3
Because the remainders are the digits of the base 8 expansion of 12345, it follows that
Example4: Find the hexadecimal expansion of (177130)Solution: 177130 = 16.11070 +10
11070 = 16.691 + 14691 = 16.43 + 3
43 = 16.2 + 112 = 16.0 + 2
10
810 3007112345 !
10
1610 )32()177130( EA B so !
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 22/28
Example: Find the binary expansion of (241)Solution: 241 = 2.120 + 1
120 = 2.60 + 060 = 2.30 + 0
30 = 2.15 + 015 = 2.7 + 17 = 2.3 + 13 = 2.1 + 11 = 2.0 + 1
S0
10
210 )11110001()241( !
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 23/28
Section 3.8: Matrices
Definition1: A matrices is a rectangular array of numbers. A matrix with rows m and ncolumn is called an mXn matrix.
Remarks: 1- A matrix with the same number of rows as column is called square.2- The matrices are equal if they have the same number of rows and the same number
of columns and the corresponding entries in every position are equal.Example: The matrix is a 3X2 matrix
The matrix is a square matrix 2X2 matrixDefinition: Addition of matricesLet be mXn matrices. The sum of A and B, denoted by
A+B is the mXn matrix that has as its (i,j) the element. A+B=Remark: Addition of matrices id defined if the matrices are of same sizeExample: Add
¼½
»¬«
¼
¼¼
½
»
¬
¬¬«
01
42
31
20
11
? A ? Aijij bandBa A !!
ijij ba ][
ijij
ba
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 24/28
Definition: multiplication of matricesLet A be an mXk matrix and B be a kXn matrix. The product of A and B, denoted by AB
is the mXn matrix with its (i,j) the entry equal to the sum of the product of thecorresponding elements from the i th row of A and the j th column of B.
Remark: Multiplication of matrices is not commutative.Example:
Find AB if it is defined A is 4X3 B is 3X2 so AB is defined and is 4X2 matrix.
3323
211
031
143
43
22
01
252
313
244
201413
033212
114031
211
031
143
043
322
101
X X
d efined not is
Add
¼¼¼
½
»
¬¬¬«
¼¼¼
½
»
¬¬¬«
¼¼¼
½
»
¬¬¬«
!
¼¼¼
½
»
¬¬¬«
!
¼¼¼
½
»
¬¬¬«
¼¼¼
½
»
¬¬¬«
? A k jik j jiijij bababacwherec A B !! .....21211
¼¼¼
½
»
¬¬¬«
!
¼¼¼
½
»
¬¬¬«
!
03
11
42
220
112
401
and Blet A
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 25/28
example:
¼¼¼¼
½
»
¬¬¬¬«
!
¼¼¼¼
½
»
¬¬¬¬«
!
¼¼¼
½
»
¬¬¬«
¼¼¼¼
½
»
¬¬¬¬«
28
137
98
414
)0(2)1(2)4(0)3(2)1(2)2(0
)0(0)1)(1()4(3)3(0)1)(1()2(3
)0)(1()1)(1()4(2)2)(1()1)(1()2(2
)0(41041341021
03
11
42
220
013
112
401
AB
BA so AB
BA ABS olution
BA ABdoes
and Blet A
{
¼½
»
¬
«
!¼½
»
¬
«
!
!
¼½
»¬«
!¼½
»¬«
!
23
34
,35
23
:
?
11
12
12
11
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 26/28
Transpose of a matrix
The transpose of the matrix is the matrix
Definition: A square matrix A is called symmetric if A=A
Example: The matrix is symmetric.
Definition: Zero-one Matrix A matrix with entries that are either 0 or 1 is called a zero- one matrix
A A A A A
matrixidentit ythecalled is I matrixThe In
r
n X n
......
1.......00
0...0001
0.....001
0.....010
0.....100
!
¼¼¼¼¼¼
½
»
¬¬¬¬¬¬«
!
¼½
»¬«
654
321
¼
¼¼
½
»
¬
¬¬«
63
52
41T
A
¼¼¼
½
»
¬¬¬«
¼¼¼
½
»
¬¬¬«
!
252
313
234
232
514
234
for AT
T
¼¼¼
½
»
¬¬¬«
010
101
011
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 27/28
Read definition8 from the book page 252Example: Find the join and meet of the zero matricesSolution: joint of A and B is
The meet of A and B is
Example: Find the Boolean product of A and B where
°®̄ !!!�
°¯® !!
!�
otherwisebor bif bb
otherwise
bbif bb
0111
0
11
2121
21
21
¼½
»¬«
!¼½
»¬«
!011
010,
010
101 B A
¼½»¬«!¼
½»¬«
���
���!�011111
001110011001 B A
¼
½
»¬«
!¼
½
»¬«
���
���!�
010
000
001110
011001 B A
¼½
»¬«
!
¼¼¼
½
»
¬¬¬«
!110
011
01
10
01
and B A
8/6/2019 Introduction to Discrete Mathematics Ch3
http://slidepdf.com/reader/full/introduction-to-discrete-mathematics-ch3 28/28
Solution: The Boolean product of A and B denoted by is
Remark:1- let A be a square zero- one matrix then2- note that
Example:
B A �
¼¼
¼
½
»
¬¬
¬«
!
¼¼¼
½
»
¬¬¬«
���
���
���
!
¼¼¼
½
»
¬¬¬«
���������
���������
���������
!5
011110
011
000101
101000
000101
100110110011
110011100110
100110110011
B A
? A A A A A A r ���! .....
? A In A !0
? A
? A
¼
¼¼
½
»
¬
¬¬«
!�!
¼¼¼
½
»
¬¬¬«
!
101
100
011
011
001
100
2
2
A A A
A find let A