[Hernandez 1213A] Cs30 day08

Page 1

Counting

CS 30 : Discrete Mathematics for Computer Science First Semester, AY 2012-2013

https://sites.google.com/a/dcs.upd.edu.ph/nhsh_classes/cs 30

sablay-logo

Nestine Hope S. Hernandez Algorithms and Complexity Laboratory Department of Computer Science University of the Philippines, Diliman nshernandez@dcs.upd.edu.ph updilseal

Day 8

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Combinatorics and Computing

sablay-logo

1

Counting Basic Counting Principles

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation how much storage is required

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation how much storage is required determining the number of items of a particular type that have to be

sablay-logo

stored

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation how much storage is required determining the number of items of a particular type that have to be

sablay-logo

stored

length of program execution time

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation how much storage is required determining the number of items of a particular type that have to be

sablay-logo

stored

length of program execution time how many operations the computation involves

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

In applications of computer to problems ...

potential cost of the computation how much storage is required determining the number of items of a particular type that have to be

sablay-logo

stored

length of program execution time how many operations the computation involves

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example,

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example, number of ways of visiting each of n cities exactly once by starting and nishing each trip at a given city?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example, number of ways of visiting each of n cities exactly once by starting and nishing each trip at a given city? A straightforward way of nding the shortest round trip:

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example, number of ways of visiting each of n cities exactly once by starting and nishing each trip at a given city? A straightforward way of nding the shortest round trip: (exhaustive searching/complete enumeration)

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example, number of ways of visiting each of n cities exactly once by starting and nishing each trip at a given city? A straightforward way of nding the shortest round trip: (exhaustive searching/complete enumeration) how many operations?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

How many?

For example, number of ways of visiting each of n cities exactly once by starting and nishing each trip at a given city? A straightforward way of nding the shortest round trip: (exhaustive searching/complete enumeration) how many operations? how long?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Sum

The principle of disjunctive counting The number of ways to choose an element from one of n disjoint sets , . . . , A is the sum of the cardinalities of the sets

A ,A 1

2

n

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Sum

The principle of disjunctive counting The number of ways to choose an element from one of n disjoint sets , . . . , A is the sum of the cardinalities of the sets S i.e. | A | = |A | + |A | + · · · + |A | where |A ∩ A | = 0, ∀i , j

A ,A 1

2

n

n

i

i

1

2

n

i

j

=1

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Sum

The principle of disjunctive counting The number of ways to choose an element from one of n disjoint sets , . . . , A is the sum of the cardinalities of the sets S i.e. | A | = |A | + |A | + · · · + |A | where |A ∩ A | = 0, ∀i , j

A ,A 1

2

n

n

i

i

1

2

n

i

j

=1

Example : How many ways can we get an even sum when two distinguishable dice are rolled?

sablay-logo

1

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Sum

The principle of disjunctive counting The number of ways to choose an element from one of n disjoint sets , . . . , A is the sum of the cardinalities of the sets S i.e. | A | = |A | + |A | + · · · + |A | where |A ∩ A | = 0, ∀i , j

A ,A 1

2

n

n

i

i

1

2

n

i

j

=1

Example : How many ways can we get an even sum when two distinguishable dice are rolled? How many ways can we get an even sum when two indistinguishable dice are rolled?

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e 路 路 路 e ways 1

2

n

1

2

n

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e · · · e ways Q i.e. | A | = |A | × |A | × · · · × |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e · · · e ways Q i.e. | A | = |A | × |A | × · · · × |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

sablay-logo

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? 1

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e · · · e ways Q i.e. | A | = |A | × |A | × · · · × |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

sablay-logo

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? Suppose license plates require 3 English letters followed by 3 digits. 1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e ¡ ¡ ¡ e ways Q i.e. | A | = |A | Ă— |A | Ă— ¡ ¡ ¡ Ă— |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

sablay-logo

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? Suppose license plates require 3 English letters followed by 3 digits. (a) How many di erent plates can be manufactured if repetition of letters and digits are allowed? 1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e ¡ ¡ ¡ e ways Q i.e. | A | = |A | Ă— |A | Ă— ¡ ¡ ¡ Ă— |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? Suppose license plates require 3 English letters followed by 3 digits. (a) How many di erent plates can be manufactured if repetition of letters and digits are allowed? (b) How many plates are possible if only the letters can be repeated?

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e ¡ ¡ ¡ e ways Q i.e. | A | = |A | Ă— |A | Ă— ¡ ¡ ¡ Ă— |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? Suppose license plates require 3 English letters followed by 3 digits. (a) How many di erent plates can be manufactured if repetition of letters and digits are allowed? (b) How many plates are possible if only the letters can be repeated? (c) How many plates are possible if only the digits can be repeated?

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Rule of Product

The principle of sequential counting If a rst object can be chosen in e ways, a second object in e ways, ... and an nth object in e ways, then a choice of a rst, a second, ... and an nth object can be made in e e ¡ ¡ ¡ e ways Q i.e. | A | = |A | Ă— |A | Ă— ¡ ¡ ¡ Ă— |A | 1

2

n

1

2

n

n

i

i

1

2

n

=1

Example : How many possible outcomes are there if 3 distinguishable dice are rolled? Suppose license plates require 3 English letters followed by 3 digits. (a) How many di erent plates can be manufactured if repetition of letters and digits are allowed? (b) How many plates are possible if only the letters can be repeated? (c) How many plates are possible if only the digits can be repeated? (d) How many are possible if no repetitions are allowed at all?

sablay-logo

1

2

Discrete Mathematics for Computer Science

CS 30

updilseal

dcs-logo

acl-logo


Counting

Basic Counting Principles

More examples 1

How many di erent license plates are there that involve 1, 2, or 3 letters followed by 4 digits (where repetitions are allowed)?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

More examples 1

2

How many di erent license plates are there that involve 1, 2, or 3 letters followed by 4 digits (where repetitions are allowed)? How many three digit numbers are there which are even and have no repeated digits?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Indirect Counting

By counting the complement of the set 1

Suppose that we draw a card from a deck of 52 cards and replace it before the next draw. In how many ways can 10 cards be drawn so that the tenth card is a repetition of a previous draw?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

Indirect Counting

By counting the complement of the set 1

2

Suppose that we draw a card from a deck of 52 cards and replace it before the next draw. In how many ways can 10 cards be drawn so that the tenth card is a repetition of a previous draw? In how many ways can 10 people be seated so that a certain pair of them are not next to each other?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. 1

2

1

2

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. To correctly count the number of ways to do the two tasks, we add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n ways and the set of n ways. 1

2

1

2

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. To correctly count the number of ways to do the two tasks, we add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n ways and the set of n ways. i.e. |A ∪ B | = |A| + |B | − |A ∩ B | 1

2

1

2

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. To correctly count the number of ways to do the two tasks, we add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n ways and the set of n ways. i.e. |A ∪ B | = |A| + |B | − |A ∩ B | (we can extend the rule to more than two elements) 1

2

1

2

sablay-logo

1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. To correctly count the number of ways to do the two tasks, we add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n ways and the set of n ways. i.e. |A ∪ B | = |A| + |B | − |A ∩ B | (we can extend the rule to more than two elements) 1

2

1

2

sablay-logo

1

2

Example : How many bit strings of length eight either start with a 1 bit or end with the two bits 00? 1

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

The Inclusion-Exclusion Principle

Suppose that a task can be done in n or in n ways, but that some of the set of n ways to do the task are the same as some of the n other ways to do the task. To correctly count the number of ways to do the two tasks, we add the number of ways to do it in one way and the number of ways to do it in the other way, and then subtract the number of ways to do the task in a way that is both among the set of n ways and the set of n ways. i.e. |A ∪ B | = |A| + |B | − |A ∩ B | (we can extend the rule to more than two elements) 1

2

1

2

sablay-logo

1

2

Example : How many bit strings of length eight either start with a 1 bit or end with the two bits 00? A computer company receives 350 applications for a job. Suppose that 220 of these people majored in computer science, 147 majored in business, and 51 majored both in computer science and in business. How many of these applicants majored neither in computer science nor in business? 1

2

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

One-to-One Correspondence

In this technique the problem at hand is replaced by another problem where it is observed that there are exactly the same number of objects of the rst type as there are of the second type.

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

One-to-One Correspondence

In this technique the problem at hand is replaced by another problem where it is observed that there are exactly the same number of objects of the rst type as there are of the second type. 1

Suppose that there are 101 players entered in a single elimination tennis tournament. In such a tournament, any player who loses a match must drop out, and every match ends in a victory for some player (that is, no ties). In each round of the tournament, the players remaining are matched into as many pairs as possible, but if there is an odd number of players left someone receives a bye (that is, an automatic victory for this player in this round). Enough rounds are played until a single player remains who wins the tournament. How many matches must be played in total?

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

Basic Counting Principles

One-to-One Correspondence

In this technique the problem at hand is replaced by another problem where it is observed that there are exactly the same number of objects of the rst type as there are of the second type. 1

2

Suppose that there are 101 players entered in a single elimination tennis tournament. In such a tournament, any player who loses a match must drop out, and every match ends in a victory for some player (that is, no ties). In each round of the tournament, the players remaining are matched into as many pairs as possible, but if there is an odd number of players left someone receives a bye (that is, an automatic victory for this player in this round). Enough rounds are played until a single player remains who wins the tournament. How many matches must be played in total? Determine the number of subsets of a set with n elements.

sablay-logo

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Counting

sablay-logo

Questions? See you next meeting!

updilseal

dcs-logo

acl-logo Discrete Mathematics for Computer Science

CS 30


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.