Dr. Eng. Farag Elnagahy Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.

Slides:



Advertisements
Similar presentations
12 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Introduction.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
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.
College of Information Technology & Design
1 Combinatorics Rosen 6 th ed., § , § Combinatorics Count the number of ways to put things together into various combinations.Count the number.
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.
Counting Tools ● Enumeration ● Multiplication ● Addition ● Negation.
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;
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.
CS100 : Discrete Structures
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Combinatorics.
Counting Chapter 6 With Question/Answer Animations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Discrete Maths Objective to introduce some of the counting rules (product, sum, subtraction, division, pigeonhole) through examples , Semester 2,
1 Permutations and Combinations. 2 In this section, techniques will be introduced for counting the unordered selections of distinct objects and the ordered.
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.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Chapter 3 Permutations and combinations
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
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.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/37 Module.
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.
CSNB143 – Discrete Structure
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
11.1 CompSci 102© Michael Frank Today’s topics CountingCounting –Sum rule –Product rule –Tree diagrams –Inclusion/exclusion Reading: Sections 4.1Reading:
Discrete Structures Counting (Ch. 6)
Menu Traditional Menu Other Menu Nasi LemakBeef Burger Roti Canai Potatoes Chip Capati French Bread Mee Goreng Drink : Coffee, Tea, Coke and Pepsi.
Counting Principles Multiplication rule Permutations Combinations.
Counting.
Chapter 7 – Counting Techniques CSNB 143 Discrete Mathematical Structures.
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.
ICS 253: Discrete Structures I
Chapter 5, Section 5.1 The Basics of Counting
The Pigeonhole Principle
COCS DISCRETE STRUCTURES
Counting Chapter 6 With Question/Answer Animations
CS 2210 Discrete Structures Counting
CS100: Discrete structures
Discrete Structures for Computer Science
Module #15: Combinatorics
Counting techniques Basic Counting Principles, Pigeonhole Principle, Permutations and Combinations.
Module #15: Combinatorics
Discrete Mathematics and its Applications
Presentation transcript:

Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222 Discrete Structures ICounting

2 The Basics of counting Combinatorics is the mathematics of counting and arranging objects. Counting of objects with certain properties (enumeration) is required to solve many different types of problems. For example, counting is used to:  Determine number of ordered or unordered arrangement of objects. arrangement of objects.  Generate all the arrangements of a specified kind which is important in computer simulations. which is important in computer simulations.  Compute probabilities of events.  Analyze the chance of winning games, lotteries etc.  Determine the complexity of algorithms.

3 The Basics of counting Two basic counting principles The Sum Rule The Sum Rule The Product Rule The Product Rule  Let us consider two tasks: m is the number of ways to do task1 m is the number of ways to do task1 n is the number of ways to do task2 n is the number of ways to do task2 Performing task1 does not accomplish task2 and vice versa (task1 and task2 are independent of each other). Sum rule: the number of ways that “either task1 or task2 can be done, but not both”, is m+n. Sum rule: the number of ways that “either task1 or task2 can be done, but not both”, is m+n. Product rule: the number of ways that “both task1 and task2 can be done” in mn. Product rule: the number of ways that “both task1 and task2 can be done” in mn.

4 The Basics of counting (Examples) Example: A student can choose a computer project from one of three lists. The three lists contain 23, 15, and 19 possible projects respectively. How many possible projects are there to choose from? ( =57) Example: The chairs of an auditorium are to be labeled with a letter and a positive integer not to exceed 100. What is the largest number of chairs that can be labeled differently? (26x100=2600)

5 The Basics of counting (Set version) If A is the set of ways to do task1, and B the set of ways to do task2, and if A and B are disjoint, then:  The ways to do either task1 or task2 are A  B, and |A  B|=|A|+|B| A  B, and |A  B|=|A|+|B|  The ways to do both task1 and task2 are A  B, and |A  B|=|A|·|B| A  B, and |A  B|=|A|·|B| The number of different subsets of a finite set(s) is ? |s| …

6 The Basics of counting (Examples) What is the value of k after the following code has been executed? K:=0 for i 1 :=1 to n 1 K:= K +1 for i 2 =1 to n 2 K:= K +1 for i 3 =1 to n 3 K:= K +1 K= n 1 + n 2 + n 3 K:=0 for i 1 :=1 to n 1 for i 2 :=1 to n 2 for i 2 :=1 to n 2 for i 3 :=1 to n 3 for i 3 :=1 to n 3 K:= K +1 K= n 1 x n 2 x n 3

7 The Basics of counting (Examples) Count the number of print statements in this algorithm: The total number of print statements executed is n · (n+n) = 2n 2. for i := 1 to n begin begin for j := 1 to n for j := 1 to n print “hello” print “hello” for k := 1 to n for k := 1 to n print “hello” print “hello” end end

8 The Basics of counting (Examples) Count the number of print statements in this algorithm: for each i, the number of print statements executed is i in the j loop plus n−i in the k loop. Therefore, for each i, the number of print statements is i + (n−i) = n. Therefore the total number of print statements executed is n · n = n 2. for i := 1 to n begin begin for j := 1 to i for j := 1 to i print “hello” print “hello” for k := i + 1 to n for k := i + 1 to n print “hello” print “hello” end end

9 The Basics of counting (Examples) In a computer language  The name of a variable is a string of one or two alphanumeric characters.  uppercase and lowercase letters are not distinguished.  26 English letter, 10 digits.  the variable name must begin with letter.  there are five strings of two characters that are reserved for programming use. How many different variable names are there ? V 1 string (one character),V 2 string (two characters) V=V 1 +V 2 V 1 =26 V 2 =26x(26+10) – 5 =26x36 –5 =931 V=26+931=957

10 The Basics of counting (Examples) How many different license plates are available if each plate contains a sequence of three letters followed by three digits? L 1 L 2 L 3 D 1 D 2 D 3 L 1 L 2 L 3 D 1 D 2 D 3 Each of the three letters can be written in 26 different ways, and each of the three digits can be written in 10 different ways. Hence, by the product rule, there is a total of 26  26  26  10  10  10 = 17,576,000 different license plates possible.

11 The Basics of counting (Examples) Each user on a computer system has a password, which is six to eight characters long, where each character is an uppercase letter or digit. Each password must contain at least one digit. How many passwords are there? (string includes Letters & Digits)- (string with no digits) P=P 6 +P 7 +P 8 P 6 = = P 7 = = P 8 = = P=P 6 +P 7 +P 8 =

12 The Basics of counting (Examples) In version 4 of the Internet Protocol (IPv4) The internet address is a string of 32 bits as follows: Class A address [ 0 -netid(7 bits) – hostid (24 bits)] Class B address [ 10 -netid(14 bits) – hostid (16 bits)] Class C address [ 110 -netid(21 bits) – hostid (8 bits)] Class D address [ 1110 –multicast address (28 bits)] Class E address [ address (27 bits)] Where, Network number(netid) -host number(hostid) Restrictions  is unavailable in netid  All 0s and all 1s are unavailable in hostid  The computer on the Internet has either class A or B or C addresses. How many different IPv4 addresses are available for computers on the Internet? (2 7 -1)( )+( )( )+( )(2 8 -2) (2 7 -1)( )+( )( )+( )(2 8 -2)

13 The Basics of counting (Examples) How many bit string of length eight either start with a 1 bit or end with the two bits 00? =128 ways =64 ways =32 ways = 160

14 The Basics of counting (Examples) A computer company receives 350 applications from computer graduates for a job. Suppose that 220 of these people majored in CS, 147 majored in business, and 51 majored both in CS and in business. How many of these applicants majored neither in CS nor in business? Let A 1 be the set of students who majored in CS Let A 2 be the set of students who majored in business The number of students who majored either in CS or in business (or both) is |A 1  A 2 |=|A 1 |+|A 2 |-|A 1  A 2 |= =316 The number of applicants who majored neither in CS nor in business is =34

15 The Basics of counting (Examples) Exercises PP

16 The Pigeonhole principle Suppose there are n pigeons, k pigeonholes, and n>k. If these n pigeons fly into these k pigeonholes, then some pigeonhole must contain at least two pigeons. If k+1 objects are assigned to k places, then at least 1 place must be assigned ≥2 objects. 7 pigeons 7 pigeons 6 pigeonholes 6 pigeonholes

17 The Pigeonhole principle  In terms of the assignment function: If f:A → B and |A|≥|B|+1, then some element of B If f:A → B and |A|≥|B|+1, then some element of B has ≥2 pre-images under f.( f is not one-to-one) has ≥2 pre-images under f.( f is not one-to-one)  How many students must be in 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 points? Greater than 101

18 The Pigeonhole principle (Examples) 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. If N objects are placed into k boxes, then there is at least one box containing at least  N/K  objects.  e.g., there are N=280 students in this class. There are k=52 weeks in the year. Therefore, there must be at least 1 week during which at least  280/52  =  5.38  =6 students in the class have a birthday.

19 The Pigeonhole principle (Examples)  There are 280 students in the class. Without knowing anybody’s birthday, what is the largest value of n for which we can prove that at least n students must have been born in the same month?  280/12  =  23.3  = 24  What is the minimum number of students required in a discrete math class to be sure that at least six will receive the same grade, if there are five possible grades, A, B, C, D, and F?

20 Permutations and Combinations Permutations A.In how many ways can we select 3 students from a group of 5 students to stand in line for a picture? B.In how many ways can we arrange all 5 of these students in a line for a picture? Note that the order in which we select the students matters. 5 ways to select the first student 4 ways to select the second student 3 ways to select the third student 2 ways to select the fourth student 1 way to select the fifth student A =60 B =120

21 Permutations and Combinations Permutations  A permutation of a set S of objects is an ordered arrangement of the elements of S where each element appears only once: e.g., 1 2 3, 2 1 3,  An ordered arrangement of r distinct elements of S is called an r-permutation.  The number of r-permutations of a set S with n=|S| elements is P(n,r) = n(n−1)(n−2) …(n−r+1) = n!/(n−r)!

22 Permutations and Combinations Permutations (examples)  How many ways are there to select a first-prize winner, a second-prize winner,and a third-prize winner from 100 different people who have entered a contest? P(100,3)= = How many permutations of the letters ABCDEFGH contain the string ABC ?How many permutations of the letters ABCDEFGH contain the string ABC ? ABC, D, E, F, G, H we have 6 objects ABC, D, E, F, G, H we have 6 objects Theses object can occur in any order There are 6!=720 permutations There are 6!=720 permutations

23 Permutations and Combinations Combinations  The number of ways of choosing r elements from S (order does not matter). S={1,2,3} S={1,2,3} e.g., 1 2, 1 3, 2 e.g., 1 2, 1 3, 2  The number of r-combinations C(n,r) of a set with n=|S| elements is

24 Permutations and Combinations Example S={1,2,3}, all permutations={(1,2,3),(2,1,3),(1,3,2),(2,3,1),(3,1,2),(3,2,1 )} all 2-permutations={(1,2),(2,1),(1,3),(3,1),(2,3),(3,2)} P(3,3)=3*2*1=6, P(3,2)=3*2=6 S={1,2,3}, all 2-combinations={{1,2},{1,3},{2,3}} Comparing to all 2-permutations, we see we ignore order,

25 Permutations and Combinations Example How many ways are there to choose a committee of size five consisting of three women and two men from a group of ten women and seven men?  The number of ways to choose three women is C(10, 3)  The number of ways to choose two men is C(7, 2).  Using the product rule to choose three women and two men, the answer is  C(10, 3) · C(7, 2) = 2, 520.

26 Permutations and Combinations Example A class has 20 women and 16 men. In how many ways can you (a) Put all the students in a row? (b) Put 7 of the students in a row? (c) Put all the students in a row if all the women are on the left and all the men are on the right? Solution: (a) There are 36 students. They can be put in a row in 36! ways. (b) You need to have an ordered arrangement of 7 out of 36 students. The number of such arrangements is P(36, 7). (c) You need to have an ordered arrangement of all 20 women AND and ordered arrangement of all 16 men. By the product rule, this can be done in 20!·16! ways.

27 Permutations and Combinations Exercises PP