Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS100 : Discrete Structures

Similar presentations


Presentation on theme: "CS100 : Discrete Structures"— Presentation transcript:

1 CS100 : Discrete Structures
4/21/2017 CS100 : Discrete Structures Counting(1) Dr.Saad Alabbad Department of Computer Science Tel # 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

2 Prepared by Dr.Saad Alabbad
4/21/2017 Basics of Counting Counting objects with certain properties is very important in solving many problems: How many ways are there to travel from Riyadh to Makkah by car given this map? How many license plates can be made using three letters and three digits? How many ways are there to select 2 persons from a group of 5? How many ways are there to arrange 5 books in a shelf? 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

3 Basics of Counting Product Rule
4/21/2017 Basics of Counting Product Rule a d Makkah Riyadh Taif b c e How many ways to go from Riyadh to Makkah? 6 ways=3*2 ad , ae bd , be cd , ce PRODUCT RULE: If a procedure can be broken into two tasks such that there are: • n1 ways to do the first task, • n2 ways to do the second task then there are n1 · n2 ways to do the procedure. 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

4 Basics of Counting Generalized Product Rule
4/21/2017 Basics of Counting Generalized Product Rule …… Makkah Dammam Riyadh Taif Taif n2 ni n1 How many ways to go from Dammam to Makkah? n1*n2*…ni PRODUCT RULE: If a procedure can be broken into i tasks such that there are: • n1 ways to do the first task, • n2 ways to do the second task …. ni ways to do the ith task then there are n1 · n2 · · · ni ways to do the procedure. 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

5 Basics of Counting Product Rule
4/21/2017 Basics of Counting Product Rule Example 1:Rooms of a hotel are labeled with one letter (a..z) and two digits(0..9).How many rooms can be labeled using this scheme? There are 26 ways for the first place. 10 ways for the second and 10 for the third. By the product rule the total is 26*10*10=2600 Example 2: A byte consist of 8 bits. How many different values can be represented using one byte? Each bit can have either 0 or 1. By the product rule the total is 28=256 a..z 0..9 0..9 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

6 Basics of Counting Product Rule
4/21/2017 Basics of Counting Product Rule Example 3:In example 1 , How many rooms can be labeled if labels starting with a vowel letter (a,w,i,o,u) or ending with 0 are not allowed Answer: 21*10*9 Example 4: how many ways are there to arrange 5 people in a row There are 5 ways for the first place,4 for the second, etc Total is 5*4*3*2*1=5! Example 5: How many functions are there from a set with 3 elements to a set with 4 elements? A function must assign for each element in the domain one element from the codomain so there are: 4*4*4=43 functions 21 0..9 1..9 1. 2. 3. .A .B .C .D Domain Codomain 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

7 Basics of Counting Product Rule
4/21/2017 Basics of Counting Product Rule Example 6: How many subsets are there in a set S of n elements? Arrange S in any order a1, a2, a3,…. an Take an arbitrary subset, then the first element a1 is either in this subset or not the second element a2 is either in this subset or not …. the nth element an is either in this subset or not So there are 2n possible ways to construct a subset from a set of n elements NOTE: The product rule is often phrased in terms of sets as follows: If A1, A2, . . ., Ak are finite sets then the number of elements in the Cartesian product of these sets is |A1×A1 × … × Ak|= |A1| . |A2| …..|Ak|. 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

8 Basics of Counting Sum Rule
4/21/2017 Basics of Counting Sum Rule SUM RULE: If a task can be done either in n1 ways or n2 ways where none of n1 ways is the same as any of the n2 ways then there are n1 +n2 to do the task In general, if a set of tasks can be broken into k mutually disjoint subsets of tasks A1, A2, . . ., Ak, the total number of tasks is |A1| + |A2| + · · · + |Ak|. Example 1: A university has three colleges. The colleges have 4,12 and 7 departments. In how many ways a student can choose his major? A student can choose a major by selecting a department from the first ,the second or the third college so the total is =23 ways 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

9 Basics of Counting Combining Sum Rule and Product Rule
4/21/2017 Basics of Counting Combining Sum Rule and Product Rule Example 2: How many bit strings of length 8 either start with 10 or 011? We have two cases: case 1: 10xxxxxx there are 26 ways by product rule Case 2: 011xxxxx there are 25 ways by product rule Total is by sum rule Note that it is not possible to have a string that starts with 10 and 011 at the same time 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

10 Principle of Inclusion-Exclusion (subtraction rule)
4/21/2017 Principle of Inclusion-Exclusion (subtraction rule) Example 3: How many bit strings of length 4 either start with 1 or end with 01? We have two cases: case 1: 1xxx there are 23 ways by product rule Case 2: xx01 there are 22 ways by product rule But strings of the form 1x01 are counted twice. There are 21 of these so the total is – 21=10 Case1 1xxx 1000 1001 1010 1011 1100 1101 1110 1111 Case2 xx01 0001 0101 1001 1101 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

11 Principle of Inclusion-Exclusion (subtraction rule)
4/21/2017 Principle of Inclusion-Exclusion (subtraction rule) In the previous example we have used what we call: Principle of Inclusion-Exclusion : Number of ways to do two tasks is the number of ways to do the first plus the number of ways to do the second minus the number of ways to do both. Stated in terms of sets: Let A and B be sets. The number of way to select an element from A or B is: |A  B| = |A| + |B| − |A  B| |A|=7 |B|=5 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

12 Principle of Inclusion-Exclusion (subtraction rule)
4/21/2017 Principle of Inclusion-Exclusion (subtraction rule) Example 1: How many bit strings of length 8 either start with 10 or end with 011? We have two cases: case 1: 10xxxxxx there are 26 ways by product rule Case 2: xxxxx011 there are 25 ways by product rule But strings of the form 10xxx011 are counted twice and we have 23 of these so the total is: 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

13 Principle of Inclusion-Exclusion (subtraction rule)
4/21/2017 Principle of Inclusion-Exclusion (subtraction rule) Example 2: How many ways to arrange a family of 6 people (parents + 4kids) where: A) the father must be next to the mother? There are 4*3*2*1 to arrange the kids There are 5 ways to place the parents There are 2 ways for parents to switch positions Total 2*5*(4*3*2*1)=240 by product rule B) the father is not next to the mother? Ways to arrange the family =6*5*4*3*2*1=720 product rule Ways to not arrange father next to mother= =480 inclusion-exclusion principle Question : Ways to position father somewhere left to mother? 4 3 2 1 F M M F 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

14 Counting using Tree Diagrams
4/21/2017 Counting using Tree Diagrams Example 1: How many bit strings of length 4 do not have consecutive 1s? 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

15 Counting using Tree Diagrams
4/21/2017 Counting using Tree Diagrams Example 2:Playoff of 2 teams with at most 5 games. The team that wins three games wins the playoff. 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

16 The Pigeonhole Principle: Introduction
4/21/2017 The Pigeonhole Principle: Introduction If n pigeons fly into k pigeonholes and k < n, then some pigeonhole contains at least two pigeons. Theorem (The Pigeonhole Principle): If k is a positive integer and k+1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects. Proof: We will prove it by contradiction. Suppose that none of k boxes contains more than one object. Then the total number of objects would be at most k. This is a contradiction, because there at least k+1 objects. The pigeonhole principle is also called the Dirichlet drawer principle, because the German mathematician Dirichlet often used this principle in his work. 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

17 The Pigeonhole Principle: Examples
4/21/2017 The Pigeonhole Principle: Examples Corollary : A function from a set with k+1 or more elements to a set with k elements is not one-to-one. Example 16: Among any group of 367 people, there must be at least two with the same birthday, because there are only 366 possible birthdays. Example 17: In any group of 27 English words, there must be at least two that begin with the same letter, because there are only 26 letters in English alphabet. Example 18: How many students must be in a class to guarantee that at least two students receive the same score on the final exam, if the exam is graded on a scale from 0 to 100 marks? Solution: There are 101 possible scores on the final. The pigeonhole principle shows that among any 102 students there must be at least two students with the same score. 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

18 The Pigeonhole Principle: Generalized
4/21/2017 The Pigeonhole Principle: Generalized Theorem (The Generalized Pigeonhole Principle): If N objects are placed into k boxes, then there is at least one box containing at least ⌈N/k⌉ objects. Proof: We will prove it by contradiction. Suppose that none of boxes contains more than ⌈N/k⌉ -1 objects. Then the total number of objects is at most k(⌈N/k⌉-1) < k((N/k+1) – 1) = N. where the inequality ⌈N/k⌉ < (N/k)+1 has been used. This is a contradiction, because there a total of N objects. Example 19: Among 100 people, there are at least ⌈100/12⌉ = 9 who were born in the same month. Example 20: What is the minimum number of students required in CS100 to be sure that at least six receive the same grade, if there nine possible grades A+, A, B+, B, C+, C, D+, D and F? Solution: ⌈N/9⌉ = 6. The smallest integer is N = = 46 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

19 Permutations: Definition
4/21/2017 Permutations: Definition Def: A permutation is an ordered arrangement of objects. The number of permutations of r distinct objects chosen from n distinct objects is denoted P(n,r) or nPr. P(n,r) = n!/(n-r)! = n x (n-1) x (n-2) x ……..x (n-r+1) If repetitions are allowed, then P(n,r) = nr. Example 21: In a running race of 12 runners, each of the top 5 finishers receives a different medal. How many ways are there to award the 5 medals? Solution: Total is 12x11x10x9x8 12 11 10 9 8 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

20 Permutations: Examples
4/21/2017 Permutations: Examples Example 22: A salesman has to visit 8 cities. The trip needs to start at a specified city. How many ways the person can visit the 7 cities? Solution: Total number of ways is P(7,7) = 7! = 5040. Example 23: How many permutations of the letters ABCDEFGH contain the string ABC? Solution: Because the letters ABC must occur as a block, we can find the answer by finding the number of permutations of six objects, namely, the block ABC, and the individual letters D, E, F, G, and H. Because this six objects can occur in any order, there are 6! = 720 permutations of the letters ABCDEFGH in which ABC occurs as a block. 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

21 Permutations: Examples
4/21/2017 Permutations: Examples Example 24: Suppose you have time to listen to 10 Surah recitation from the Holy Quran daily. There are 6 Surah by Abdullah, 8 by Badr, and 3 by Saleh to choose from. How many different playlists can you make? Solution: P(17,10) = 17x16x15x14x13x12x11 Example 25: Suppose you have time to listen to 10 Surah recitation from the Holy Quran daily. There are 6 Surah by Abdullah, 8 by Badr, and 3 by Saleh to choose from. How many different playlists can you make? Now suppose you want to listen 4 Surah by Abdullah, 4 by Badr, and 2 by Saleh, in the order. How many playlists can you make? Solution: P(6,4) x P(8,4) x P(3,2) 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

22 Combinations: Definition
4/21/2017 Combinations: Definition Def: A combination is an unordered selection of elements from some set. The number of combinations of r distinct objects chosen from n distinct objects is denoted by C(n,r) or nCr or , and is read “n choose r.” C(n,r) = P(n,r)/r! = n!/((n-r)!r!) = C(n, n-r) 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

23 Combinations: Definition
4/21/2017 Combinations: Definition Difference between Permutation and Combination: Example (a): A basketball squad consists of 12 players, 5 of which make up a team. How many different teams of players can you make from the 12? Solution: Total number of ways is C(12, 5). Example (b): In a running race of 12 runners, each of the top 5 finishers receives a different medal. How many ways are there to award the 5 medals? Solution: Total number of ways is P(12, 5). 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

24 Combinations: Questions
4/21/2017 Combinations: Questions Example 26: Suppose you have to select 11 students for a football team. There are 6 students in group-1, 8 students in group-2, and 3 students in group-3 to choose from. How many different football team can you make? Solution: Total number of ways is C(17,11) Example 27: Suppose you have to select 11 students for a football team. There are 6 students in group-1, 8 students in group-2, and 3 students in group-3 to choose from. Now suppose you want to select 4 from group-1, 5 from group-2, and 2 from group-3 in that team. How many different football team can you make? Solution: Total number of ways is C(6,4) x C(8,5) x C(3,2) 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

25 Combinations: Questions
4/21/2017 Combinations: Questions Q 2: Suppose you have to select 11 students for a football team. There are 19 students in group-1, and 23 students in group-2. (i) In how many ways can 5 from group-1 and 6 from group-2 be selected? (ii) In how many ways can a team with exactly 1 from group-1 be selected? (iii) In how many ways can a team with at most 1 from group-1 be selected? (iv) In how many ways can a team with at least 1 from group-1 be selected? 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

26 Binomial Coefficients: The Binomial Theorem
4/21/2017 Binomial Coefficients: The Binomial Theorem (a + b)2 = a2 + 2ab + b2 (a + b)3 = a3 + 3ab2 + 3a2b + b3 (a + b)4 = a4 + 4ab3 + 6a2b2 + 4a3b + b4 Why am I showing this to you? Beautiful patterns Recursive definition New type of proof Applications in more complex counting techniques 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

27 Binomial Coefficients: The Binomial Theorem
4/21/2017 Binomial Coefficients: The Binomial Theorem Binomial Theorem: Let x and y be variables, and let n be any nonnegative integer. Then Binomial coefficient Select j x’s from (x +y)n Example 28: What is the expansion of (x + y)4? Solution: From the Binomial Theorem it follows that 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

28 Binomial Coefficients: The Binomial Theorem
4/21/2017 Binomial Coefficients: The Binomial Theorem Example 29: What is the coefficient of x12y13 in the expansion of (x + y)25? Solution: From the Binomial Theorem, the coefficient is Example 30: What is the coefficient of x12y13 in the expansion of (2x - 3y)25? Solution: This expression equals (2x + (-3y))25. By the Binomial Theorem, we have The coefficient x12y13 is obtained by putting j = 13. 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

29 Binomial Coefficients: The Binomial Theorem
4/21/2017 Binomial Coefficients: The Binomial Theorem Example 31: Let n be a nonnegative integer. Then prove that Proof: Using Binomial Theorem with x = 1, y = 1, we get Example 32: Let n be a positive integer. Then prove that Proof: Using Binomial Theorem with x = 1, y = -1, we get Q 3: Let n be a nonnegative integer. Then prove that 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

30 Prepared by Dr. Zakir H. Ahmed
4/21/2017 End of Chapter IV 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed


Download ppt "CS100 : Discrete Structures"

Similar presentations


Ads by Google