MathCSE 1019 Discrete Mathematics for Computer Science Fall

  • Slides: 24
Download presentation
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011 Suprakash Datta datta@cse. yorku. ca

Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011 Suprakash Datta datta@cse. yorku. ca Office: CSEB 3043 Phone: 416 -736 -2100 ext 77875 Course page: http: //www. cse. yorku. ca/course/1019 12/26/2021 1

Counting Many applications. E. g. : • How many factors does an integer have?

Counting Many applications. E. g. : • How many factors does an integer have? • How many trailing zeroes are there in 150! ? • How many case-sensitive alphanumeric passwords are there of length k? • How many binary functions with n binary inputs are there? 12/26/2021 2

The product rule • If 2 independent subtasks can be done in m, n

The product rule • If 2 independent subtasks can be done in m, n ways (resp. ) then the task can be done in mn ways. • E. g. If I have 2 keyboard players and 3 percussionists, I can choose a keyboard -percussion duo in 6 ways. • E. g. 2: How many 2 digit numbers are there? • E. g. 3: No of k character alphanumeric passwords 12/26/2021 3

Counting functions Binary output: • One binary input: 22 functions • One integer input:

Counting functions Binary output: • One binary input: 22 functions • One integer input: 2 MAXINT functions n 2 • n binary inputs: 2 functions Integer output: • One integer input: MAXINT functions 12/26/2021 4

Binary strings • Number of binary strings of length n? easy. • Number of

Binary strings • Number of binary strings of length n? easy. • Number of subsets of a set of n elements? Relate to previous question…. Each subset is uniquely determined by a binary indicator string of length n…. 12/26/2021 5

Number of factors • How many factors of 2 n are there? • Wrong

Number of factors • How many factors of 2 n are there? • Wrong argument: each 2 may or may not be chosen…. • Correct argument: we can take 0, 1, . . , n of the 2’s. Therefore n+1 factors (including 1 and 2 n itself). 12/26/2021 6

Number of factors (general) Q: How many factors of m are there? A: Let

Number of factors (general) Q: How many factors of m are there? A: Let m = 2 a 3 b 5 c…. Then the number of factors (including 1 and m itself) is (a+1)(b+1)(c+1). . Proof: we can take 0, 1, . . , a of the 2’s, 0, 1, . . , b of the 3’s and so on. 12/26/2021 7

Powers of 2 Q: How many factors of 2 does 9! have? A: 7

Powers of 2 Q: How many factors of 2 does 9! have? A: 7 Q: How many factors of 2 does n! have? A: (n div 2) + (n div 4) + (n div 8) +… (div gives the integer quotient) 12/26/2021 8

Number of trailing zeroes Q: How many trailing zeroes in 150! ? A: Equal

Number of trailing zeroes Q: How many trailing zeroes in 150! ? A: Equal to the number of factors of 10. There are many more 2’s than 5’s so it is enough to count the number of 5’s in the factorization. So the answer is (150 div 5) + (150 div 25) + (150 div 125) 12/26/2021 9

The sum rule • If a job can be done in one of m

The sum rule • If a job can be done in one of m ways or (exclusive or) in one of n ways, the total number of ways is m+n • E. g. If you must take 3 credits of Math or 3 credits of Physics (but not both) an there are m Math courses and p Physics courses, there is a total of m+p courses to choose from. • Often used together with the product rule 12/26/2021 10

Counting strings • What is the number of binary strings of length 4 containing

Counting strings • What is the number of binary strings of length 4 containing exactly one 1? • What is the number of 4 character DNA sequences containing exactly 1 A? 12/26/2021 11

More complex problems Q: How many 2 digit numbers are multiples of 11 or

More complex problems Q: How many 2 digit numbers are multiples of 11 or 13? A: 9 (multiples of 11) + 7 (multiples of 13) Harder question: How many 3 digit numbers are multiples of 11 or 13? The problem is 143 (and its multiples) are multiples of both! 12/26/2021 12

Inclusion-Exclusion (or the subtraction rule) |A B| = |A|+|B| - |A B| • e.

Inclusion-Exclusion (or the subtraction rule) |A B| = |A|+|B| - |A B| • e. g. How many 3 digit numbers are multiples of 11 or 13? • A: No of 3 digit multiples of 11 + No of 3 digit multiples of 13 – No of 3 digit multiples of 143. • In how many ways can you toss two dice, so that the first toss is a 1 OR the last toss is a 6? 12/26/2021 13

A common trick Q 1: How many 5 element DNA sequences do not contain

A common trick Q 1: How many 5 element DNA sequences do not contain a C? A: 35 Q 2: How many 5 element DNA sequences contain at least one C? Hint: Use the previous answer. Q 3: What is the number of length 5 alphanumeric strings with at least one digit? 12/26/2021 14

Exercises • Q 16, 22, 26, 32, 41, 42, 46 12/26/2021 15

Exercises • Q 16, 22, 26, 32, 41, 42, 46 12/26/2021 15

The Pigeonhole Principle If n+1 balls are but into n bins, some bin contains

The Pigeonhole Principle If n+1 balls are but into n bins, some bin contains more than 1 ball. • Do not be misled by the simplicity of the principle – this is a powerful statement! E. g. • EASY: In any group of 367 people, at least 2 share a birthday • HARD: For every integer n there is a multiple of n that has only 0, 1’s in its decimal expansion. 12/26/2021 16

Generalization • If n balls are put into m bins then some bin contains

Generalization • If n balls are put into m bins then some bin contains at least n/m balls • VERY non-trivial examples are 10, 11, 12 on page 403. 12/26/2021 17

Examples • Q 40, page 406. Prove that at a party with at least

Examples • Q 40, page 406. Prove that at a party with at least 2 people, there are 2 people who know exactly the same number of people there. • Q 44, page 406. 51 houses on a street have numbers 00 through 99 (inclusive). At least 2 houses must have consecutive numbers. 12/26/2021 18

Permutations • Part of Combinatorics • P(n, r): number of ways in which r

Permutations • Part of Combinatorics • P(n, r): number of ways in which r students (out of a class of n) can be lined up for a picture. • P(n, n) = n! • P(n, r) = n!/(n-r)! Recall that 0! = 1 by definition. 12/26/2021 19

Combinations • C(n, r): Number of ways r students can be chosen from a

Combinations • C(n, r): Number of ways r students can be chosen from a class on n students • P(n, r) = C(n, r) P(r, r) • C(n, r) = 12/26/2021 n!/[r!(n-r)!] 20

Examples • Q 22, pg 414: How many permutations of the letters ABCDEFG cointain

Examples • Q 22, pg 414: How many permutations of the letters ABCDEFG cointain the string BCD? • How many binary strings of length n contain exactly k 1’s? • Q 32, pg 414: How many strings of 6 lowercase letters contain the letter a? 12/26/2021 21

Binomial Coefficients n (x+y)n = C(n, r) xn-r yr r=0 • We will not

Binomial Coefficients n (x+y)n = C(n, r) xn-r yr r=0 • We will not prove it formally • It follows that C(n, r) = 2 n • And (-1)n C(n, r) = 0 • And C(n, r) 2 r = 3 n 12/26/2021 22

An important identity • C(n, r)+C(n, r-1) = C(n+1, r) • Direct proof (done

An important identity • C(n, r)+C(n, r-1) = C(n+1, r) • Direct proof (done on board) • Combinatorial proof: Choosing r items from a set of n+1 items (details on board) • Note: Use the above for computing C(n, r) in a program…it uses only additions and often avoids overflow issues 12/26/2021 23

Pascal’s triangle • See http: //www. mathsisfun. com/pascals-triangle. html for more facts 12/26/2021 24

Pascal’s triangle • See http: //www. mathsisfun. com/pascals-triangle. html for more facts 12/26/2021 24