24
CSCI 115 Chapter 3 Counting

CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

Embed Size (px)

Citation preview

Page 1: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

CSCI 115

Chapter 3

Counting

Page 2: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

CSCI 115

§3.1

Permutations

Page 3: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.1 – Permutations

• Theorem 3.1.1 – Multiplication Principle of Counting– Suppose 2 tasks t1 and t2 are to be performed in

sequence. If t1 can be performed in n1 ways, and t2 can be performed in n2 ways, then the sequence of tasks t1t2 can be performed in n1n2 ways.

Page 4: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.1 – Permutations

• Theorem 3.1.2– Suppose tasks t1, t2, …, tk are to be performed in

sequence. If t1 can be performed in n1 ways, t2 can be performed in n2 ways and so on, then the sequence of tasks t1t2…tk can be performed in

n1n2…nk ways.

Page 5: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.1 – Permutations

• Consider the following problem:– How many different sequences, each of length

r, can be formed from the elements of a set A if:• Elements can be repeated• Elements in the sequence must be distinct

– Number of permutations of n objects taken r at a time

Page 6: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.1 – Permutations

• Theorem 3.1.3– Let A be a set with n elements, r Z+, with

1 r n. The number of sequences of length r that can be formed from elements of A, allowing repetitions, is nr.

Page 7: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.1 – Permutations

• Theorem 3.1.4– Let A be a set with n elements, r Z+, with

1 r n. The number of permutations of n objects taken r at a time is:n.(n – 1).(n – 2)...(n – (r – 1)) and is denoted nPr.

– Equivalently:

n! . (n – r)!

• Factorials

Page 8: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

CSCI 115

§3.2

Combinations

Page 9: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.2 – Combinations

• Consider the following problem:– Let A be any set with n elements, 1 r n,

r Z+. How many different subsets of r elements are there?• Number of combinations of n objects taken r at a

time

Page 10: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.2 – Combinations

• Theorem 3.2.1– Let A be a set with |A| = n. Let r Z+ with

1 r n. The number of combinations of n objects taken r at a time is

n! . r!(n – r)!

and is denoted nCr.

Page 11: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

CSCI 115

§3.4

Elements of Probability

Page 12: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Deterministic Experiment– Outcome should not change

• Finding acceleration due to gravity

• Probabilistic Experiment– Outcome can change

• Rolling a die and recording the outcome

• We will be discussing probabilistic experiments

Page 13: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Sample space

• Event– Subset of sample space– Certain event– Impossible Event

• Mutually exclusive events

Page 14: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Notation - Assigning probabilities to events– P(E)

• Frequency– If you have n experiments and E occurs nE

times, then:• fE = nE/n is the Frequency of occurrence of E in n

trials• fE P(E) as n

Page 15: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Probability Spaces• Axioms for a probability space A:

– P1: 0 P(E) 1 E A– P2: P(A) = 1 and P() = 0– P3: If E1, E2, …, Ek are all mutually exclusive, then:

P(E1 E2 … Ek) = P(E1) + P(E2) + … + P(Ek)

Page 16: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Probability Spaces– Elementary Events (xi)

– Elementary Probability (Pi = P({xi}))

• All the xi are mutually exclusive, and we have:– EP1: 0 Pi 1– EP2: P1 + P2 + … + Pn = 1

Page 17: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Equally likely outcomes– |A| = n, and all elementary events are equally

likely, then:

If E = {x1, x2, …, xk} then P(E) = k/nor P(E) = |E|/|A|

Page 18: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.4 – Elements of Probability

• Expected value– Sum of the value of each outcome times its probability– A way to calculate the ‘average’ value

Page 19: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

CSCI 115

§3.5

Recurrence Relations

Page 20: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.5 – Recurrence Relations

• Recall sequences– Recursive– Explicit

• Recurrence relation– When an equivalent explicit formula is needed,

the recursive formula is called a recurrence relation

Page 21: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.5 – Recurrence Relations

• Backtracking– ‘Track’ the equation ‘back’ to an explicit

formula– Does not always work

Page 22: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.5 – Recurrence Relations

• Linear Homogeneity– A recurrence relation is linearly homogenous of

degree k if:• an = r1an-1 + r2an-2 + … + rkan-k

• ri is constant i– A recurrence relation that is linearly

homogenous of degree k has the following characteristic equation:• xk = r1xk-1 + r2xk-2 + … + rk

• The characteristic equation plays a role in determining the explicit formula

Page 23: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.5 – Recurrence Relations

• Theorem 3.5.1– If the characteristic equation x2 – r1x – r2 = 0 of the

recurrence relation an = r1an-1 + r2an-2 has 2 distinct roots s1 and s2, then an = us1

n + vs2n (where u and v depend on

initial conditions) is the explicit formula for the sequence.

– If the characteristic equation x2 – r1x – r2 = 0 of the recurrence relation an = r1an-1 + r2an-2 has a single root s, then an = usn + vnsn (where u and v depend on initial conditions) is the explicit formula for the sequence.

Page 24: CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations

§3.5 – Recurrence Relations

• Algorithm for solving a linearly homogenous recurrence relation1. Determine if the recurrence relation is linearly homogenous, and

if so, determine its degree

2. Find and solve the corresponding characteristic equation

3. Use the appropriate part of the theorem to determine which template to use

4. Find and solve the corresponding system of equations

5. Write out the corresponding explicit sequence

6. Check at least one term to ensure the recursive and explicit sequences generate the same value