CSCE 222 Lecture 19

From Notes
Jump to navigation Jump to search

« previous | Wednesday, March 9, 2011 | next »


Counting

Lecture Notes


Product Rule

Suppose a procedure can be broken into two tasks:

  • there are m ways to do the first task, and
  • for each of these ways, there are n ways to do the second task.

Therefore, the total number of possible tasks is m×n


Number of Possible Functions

Suppose that f:AB is a function from a set A with |A|=m elements to B with |B|=n elements. How many possible functions exist?

n×n××nm=nm


Sum Rule

S is union of 2 non-overlapping finite sets A and B: |S|=|A|+|B|


Example

Each user has a password 6-8 characters long, where each character is an uppercase letter or a digit. Each password must contain at least one digit. How many possible passwords are there?

Let P be number of passwords, Pk is the number of passwords with length k, hence P=P6+P7+P8.

Pk=36k26k: number of strings of length k with digits or uppercase letters − number of strings that contain only letters.

Therefore, P=366266+367267+368268

Inclusion/Exclusion

|AB|=|A|+|B||AB|

How many bit strings of length 8 either start with 1 or end with 00?

Let A be the set of bit strings of length 8 that start with 1. Then |A|=27

Let B be the set of strings of length 8 that end with 00. Then |B|=26

|AB|=25, the number of strings that start with 1 and end in 00.

Therefore, |AB|=27+2625


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 objects.

Example: Among 367 people, there must be at least two people who share the same birthday. Max of 366 days in a (leap) year.


Example: For every positive integer n, there is a multiple of n that contains only the numbers 0 and 1.

Proof: Consider the n+1 integers 1,11,,111n+1. Dividing each by n yields at most n possible remainders. Since we have n+1 numbers, two must share the same remainder... What does this mean?


Sequences

A set of numbers.

subsequence
a sequence formed by removing some elements of a larger sequence while maintaining a certain order.
strictly increasing
for all numbers in a sequence, the next number is larger than all before it.
strictly decreasing
for all numbers in a sequence, the next number is smaller than all before it.

Example

Proof. Seeking a contradiction, we assume that there exists a sequence S=(a1,,an2+1) that does not contain any strictly increasing (or decreasing) subsequence of length n+1 or longer.

Let ik be the length of the longest increasing subsequence starting at ak. Let dk be the length of the longest decreasing subsequence starting at ak.

Notice that 1 ≤ ik,dkn, so there are n2 distinct ordered pairs

Since all elements of the sequence are distinct real numbers, we either have as<at or as>at, where as and at are two elements in our sequence.


Permutations

A permutation of a set of distinct elements is an ordered arrangement of these objects:

S={1,2,3}{3,1,2}a permutation

If we decide to rearrange r elements in S, then it is called an r-permutation.

Let P(n,r) denote the number of r-permutations of a set containing n elements.

Simple Example

P({1,2,3},2)=|{{1,2},{1,3},{2,1},{2,3},{3,1},{3,2}|=3 ways to choose first element×2 ways to choose the second element=6 by product rule


In General

P(n,r)=n(n1)(n2)(nr+1)=n!(nr)!

Complicated example

How many permutations of the letters A-H are there containing the string "ABC"?

Think of the phrase ABC as a single token. The other five positions can be filled with D-H. Therefore, 6!

Note: Look up lex