CS100 : Discrete Structures

Slides:



Advertisements
Similar presentations
22C:19 Discrete Math Counting Fall 2011 Sukumar Ghosh.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
COUNTING AND PROBABILITY
1 Section 4.3 Permutations & Combinations. 2 Permutation Set of distinct objects in an ordered arrangement An ordered arrangement of r members of a set.
Permutations and Combinations Rosen 4.3. Permutations A permutation of a set of distinct objects is an ordered arrangement these objects. An ordered arrangement.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
The Pigeonhole Principle
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
Chapter 6 With Question/Answer Animations. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
THE BASIC OF COUNTING Discrete mathematics KNURE, Software department, Ph , N.V. Bilous.
CSE115/ENGR160 Discrete Mathematics 04/17/12
1 Section 4.1 Basics of Counting. 2 Basic Counting Principles: Sum Rule Suppose you have two tasks to perform: –The first task can be done in n 1 ways;
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
CSE115/ENGR160 Discrete Mathematics 04/10/12
CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
4.4.2 Combinations of multisets
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
Exam 1 Review 5.1, , 8.1, 8.2.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Counting Chapter 6 With Question/Answer Animations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Counting. Why counting  Determine the complexity of algorithms To sort n numbers, how many instructions are executed ?  Count the number of objects.
The Basics of Counting Section 6.1.
Counting. Product Rule Example Sum Rule Pigeonhole principle If there are more pigeons than pigeonholes, then there must be at least one pigeonhole.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
The Basics of Counting Section 6.1.
Section Section Summary The Product Rule The Sum Rule The Subtraction Rule The Division Rule Examples, Examples, and Examples Tree Diagrams.
Module #15: Combinatorics Rosen 5 th ed., §§ & §6.5 Now we are moving on to Ch. 4 It is the study of arrangement of objects e.g. enumeration, counting.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
CS 103 Discrete Structures Lecture 16
5.2 The Pigeonhole Principle
Counting.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
Section Basic Counting Principles: The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n 1.
CS 104: Discrete Mathematics
Discrete Mathematics. Exercises Exercise 1:  There are 18 Computer Science (CS) majors and 325 Business Administration (BA) majors at a college.
Section The Pigeonhole Principle If a flock of 20 pigeons roosts in a set of 19 pigeonholes, one of the pigeonholes must have more than 1 pigeon.
Chapter 6 With Question/Answer Animations Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 5 Counting 歐亞書局.
Section The Product Rule  Example: How many different license plates can be made if each plate contains a sequence of three uppercase English letters.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Section 6.3. Section Summary Permutations Combinations.
Example A standard deck of 52 cards has 13 kinds of cards, with four cards of each of kind, one in each of the four suits, hearts, diamonds, spades, and.
Lec 13 – March 10  The Basics of Counting  The Pigeonhole Principle  Permutations and Combinations  Binomial Coefficients and Identities  Generalized.
Discrete Mathematics Counting.
The Pigeonhole Principle
CSE15 Discrete Mathematics 04/19/17
ICS 253: Discrete Structures I
Chapter 5, Section 5.1 The Basics of Counting
The Pigeonhole Principle
COCS DISCRETE STRUCTURES
Permutations and Combinations
Counting Chapter 6 With Question/Answer Animations
CS 2210 Discrete Structures Counting
Recursively Defined Functions
CS100: Discrete structures
Permutations and Combinations
Representations of Integers
Presentation transcript:

CS100 : Discrete Structures 4/21/2017 CS100 : Discrete Structures Counting(1) Dr.Saad Alabbad Department of Computer Science E-mail: salabbad@gmail.com Tel # 2581888 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

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

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

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

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

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

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

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 4+12+7=23 ways 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

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 25+26 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

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 23+ 22 – 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

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

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: 26+ 25 - 23 4/21/2017 Prepared by Dr.Saad Alabbad Prepared by Dr. Zakir H. Ahmed

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=720-240=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

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

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

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

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

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 = 9.5+1 = 46 4/21/2017 Prepared by Dr. Zakir H. Ahmed Prepared by Dr. Zakir H. Ahmed

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

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

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

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

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

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

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

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

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

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

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

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