csc 281 discrete mathematics for computer science · 2015-10-05 · 10/5/2015 5 strings sequences...

33
CSC 281 Discrete Mathematics for Computer Science Dr.Yuan Tian [email protected] Sequences

Upload: others

Post on 20-Jan-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

CSC 281

Discrete Mathematics for Computer

Science

Dr.Yuan Tian

[email protected]

Sequences

Page 2: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

Sequences

Sequences represent ordered lists of elements.

A sequence is defined as a function from a subset of N to a set S. We use the notation an to denote the image of the integer n. We call an a term of the sequence.

Example:

subset of N: 1 2 3 4 5 …

S: 2 4 6 8 10 …

Page 3: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 3

Sequences

We use the notation {an} to describe a sequence.

Important: Do not confuse this with the {} used in set notation.

It is convenient to describe a sequence with a formula.

For example, the sequence on the previous slide can be specified as

{an}, where an = 2n.

Examples:

Sequence {ai}, where ai = i is just a0 = 0, a1 = 1, a2 = 2, …

Sequence {ai}, where ai = i2 is just a0 = 0, a1 = 1, a2 = 4, …

Page 4: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015

The Formula Game

1, 3, 5, 7, 9, … an = 2n - 1

-1, 1, -1, 1, -1, … an = (-1)n

2, 5, 10, 17, 26, … an = n2 + 1

0.25, 0.5, 0.75, 1, 1.25 … an = 0.25n

3, 9, 27, 81, 243, … an = 3n

What are the formulas that describe the following

sequences a1, a2, a3, … ?

Page 5: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 5

Strings

Sequences of the form a1, a2, …, an are often used in computer

science. (always check whether sequence starts at a0 or a1)

Finite sequences are also called strings, denoted by a1a2a3…an.

The length of a string S is the number of terms that it consists of.

The empty string contains no terms at all. It has length zero.

Page 6: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

6

Geometric and Arithmetic Progressions

Definition: A geometric progression is a sequence of the form

,,,,,, 32 narararara

The initial term a and the common ratio r are real numbers

Definition: An arithmetic progression is a sequence of the form

,,,3,2,, ndadadadaa

The initial term a and the common difference d are real numbers

Note: An arithmetic progression is a discrete analogue of the linear function f(x) = dx + a

Page 7: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

Notice differences in growth rate.

Page 8: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

8

Summation

The symbol (Greek letter sigma) is used to denote summation. The limit:

aii1

k

a1 a2 ak

aii1

limn

aii1

n

i is the index of the summation, and the choice of letter i is arbitrary;

the index of the summation runs through all integers, with its lower limit i

and ending upper limit k.

Page 9: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

9

Summation

The laws for arithmetic apply to summations

cai bi i1

k

c aii1

k

bii1

k

Use associativity to separate the b terms from the a terms. Use distributivity to factor the c’s.

Page 10: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 10

Summations

It is 1 + 2 + 3 + 4 + 5 + 6 = 21.

We write it as . 1000

2

1j

j

What is the value of ?

6

1j

j

It is so much work to calculate this…

What is the value of ?

100

1j

j

How can we express the sum of the first 1000 terms of the

sequence {an} with an=n2 for

n = 1, 2, 3, … ?

Page 11: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

11

Summations you should know…

What is S = 1 + 2 + 3 + … + n?

You get n copies of (n+1). But we’ve over added by a factor of 2. So just divide by 2.

S = 1 + 2 + … + n

S = n + n-1 + … + 1

2s = n+1 + n+1 + … + n+1

Write the sum.

Write it again.

Add together.

kk1

n

n(n 1)

2

(little) Gauss in 4th grade.

Why whole number?

Page 12: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 12

Arithemetic Series

How does: 1

( 1)

2

n

j

n nj

Observe that:

1 + 2 + 3 +…+ n/2 + (n/2 + 1) +…+ (n - 2) + (n - 1) + n

???

= [1 + n] + [2 + (n - 1)] + [3 + (n - 2)] +…+ [n/2 + (n/2 + 1)]

= (n + 1) + (n + 1) + (n + 1) + … + (n + 1) (with n/2 terms)

= n(n + 1)/2.

Page 13: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 13

Summations

It is said that Friedrich Gauss came up with the following formula:

1

( 1)

2

n

j

n nj

When you have such a formula, the result of any summation can be

calculated much more easily, for example:

100

1

100(100 1) 101005050

2 2j

j

Page 14: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

10/5/2015 14

Geometric Series

How does: ( 1)

0

1

( 1)

nnj

j

aa

a

Observe that:

S = 1 + a + a2 + a3 + … + an

???

aS = a + a2 + a3 + … + an + a(n+1)

so, (aS - S) = (a - 1)S = a(n+1) - 1

Therefore, 1 + a + a2 + … + an = (a(n+1) - 1) / (a - 1).

For example: 1 + 2 + 4 + 8 +… + 1024 = 2047.

Page 15: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

Double Summations

Corresponding to nested loops in C or Java, there is also double (or

triple etc.) summation:

Example: 5 2

1 1i j

ij

5

1

( 2 )i

i i

5

1

3i

i

3 6 9 12 15 45

Page 16: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

16

What is S = 1 + 3 + 5 + … + (2n - 1)?

Sum of first n odds.

(2k 1)k1

n

2 kk1

n

1k1

n

2n(n 1)

2

n

n2

Page 17: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

What is S = 1 + 3 + 5 + … + (2n - 1)?

Sum of first n odds.

n2

Page 18: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

What is S = 1 + r + r2 + … + rn

Geometric Series

rk

k 0

n

1 r rn

r rk

k0

n

r r2 rn1

Multiply by r

Subtract the summations

rk

k0

n

r rk

k0

n

1 rn1

factor

(1 r) rk

k 0

n

1 rn1 divide

rk

k 0

n

1 rn1

(1 r)DONE!

Page 19: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

What about:

rk

k 0

1 r rn

nlim

1 rn1

(1 r)

If r 1 this blows up.

If r < 1 we can say something.

rk

k 0

nlim rk

k 0

n

1

(1 r)

Try r = ½.

Page 20: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

Useful Summations

Page 21: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

21

Infinite Cardinality

How can we extend the notion of cardinality to infinite sets?

Definition: Two sets A and B have the same cardinality if and only if

there exists a bijection (or a one-to-one correspondence) between

them, A ~ B.

We split infinite sets into two groups:

1. Sets with the same cardinality as the set of natural numbers

2. Sets with different cardinality as the set of natural numbers

Page 22: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

22

Infinite Cardinality

Definition: A set is countable if it is finite or has the same cardinality

as the set of positive integers.

Definition: A set is uncountable if it is not countable.

Definition: The cardinality of an infinite set S that is countable is denotes

by 0א (where א is aleph, the first letter of the Hebrew alphabet). We

write |S| = 0א and say that S has cardinality “aleph null”.

Note: Georg Cantor defined the notion of cardinality and was the first to realize that infinite sets can have

different cardinalities. 0א is the cardinality of the natural numbers; the next larger cardinality is

aleph-one 1א, then, 2א and so on.

Page 23: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

23

Infinite Cardinality:

Odd Positive Integers

Example: The set of odd positive integers is a countable set.

Let’s define the function f, from Z+ to the set of odd positive numbers,

f(n) = 2 n -1

We have to show that f is both one-to-one and onto.

a) one-to-one

Suppose f(n)= f(m) 2n-1 = 2m-1 n=m

b) onto

Suppose that t is an odd positive integer. Then t is 1 less than an even

integer 2k, where k is a natural number. hence t=2k-1= f(k).

Page 24: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

24

Infinite Cardinality:

Odd Positive Integers

2

Page 25: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

25

Infinite Cardinality:

Integers

Example: The set of integers is a countable set.

Lets consider the sequence of all integers, starting with 0: 0,1,-1,2,-

2,….

We can define this sequence as a function:

oddNnn

evenNnn

,2

)1(

,2

f(n) =

Show at home that it’s one-to-one and onto

2 0 1 -1 2

Page 26: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

26

Infinite Cardinality:

Rational Numbers

Example: The set of positive rational numbers is a countable set. Hmm…

Page 27: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

27

Infinite Cardinality:

Rational Numbers

Example: The set of positive rational numbers is a countable set

Key aspect to list the rational numbers as a sequence – every positive number is the

quotient p/q of two positive integers.

Visualization of the proof.

p+q=4 p+q=5 p+q=6

Since all positive rational numbers

are listed once, the set of positive

rational numbers is countable.

Page 28: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

28

Uncountable Sets:

Cantor's diagonal argument

The set of all infinite sequences of zeros and ones is uncountable.

Consider a sequence,

10,,,,, 21 iin aoranaaa

For example:

So in general we have:

i.e., sn,m is the mth element of the nth sequence on the list.

Page 29: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

29

It is possible to build a sequence, say s0, in such a way that its first element is

different from the first element of the first sequence in the list, its second element is

different from the second element of the second sequence in the list, and, in general,

its nth element is different from the nth element of the nth sequence in the list. In other

words, s0,m will be 0 if sm,m is 1, and s0,m will be 1 if sm,m is 0.

Uncountable Sets:

Cantor's diagonal argument

Page 30: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

30

The sequence s0 is distinct from all the sequences in the list. Why?

Let’s say that s0 is identical to the 100th sequence, therefore, s0,100=s100,100.

In general, if it appeared as the nth sequence on the list, we would have s0,n = sn,n,

which, due to the construction of s0, is impossible.

Note: the diagonal elements are highlighted,

showing why this is called the diagonal argument

Uncountable Sets:

Cantor's diagonal argument

Page 31: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

31

From this it follows that the set T, consisting of all infinite sequences of

zeros and ones, cannot be put into a list s1, s2, s3, ... Otherwise, it would

be possible by the above process to construct a sequence s0 which would

both be in T (because it is a sequence of 0's and 1's which is by the

definition of T in T) and at the same time not in T (because we can

deliberately construct it not to be in the list). T, containing all such

sequences, must contain s0, which is just such a sequence. But since s0

does not appear anywhere on the list, T cannot contain s0.

Therefore T cannot be placed in one-to-one correspondence with the

natural numbers. In other words, the set of infinite binary strings is

uncountable.

Uncountable Sets:

Cantor's diagonal argument

Page 32: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

32

Real Numbers

Example; The set of real numbers is an uncountable set.

Let’s assume that the set of real numbers is countable.

Therefore any subset of it is also countable, in particular the interval

[0,1].

How many real numbers are in interval [0, 1]?

Page 33: CSC 281 Discrete Mathematics for Computer Science · 2015-10-05 · 10/5/2015 5 Strings Sequences of the form a 1, a 2, …, a n are often used in computer science. (always check

33

Real Numbers

How many real numbers are in interval [0, 1]?

0.4 3 2 9 0 1 3 2 9 8 4 2 0 3 9 … 0.8 2 5 9 9 1 3 2 7 2 5 8 9 2 5 … 0.9 2 5 3 9 1 5 9 7 4 5 0 6 2 1 …

“Countably many! There’s part of the list!”

“Are you sure they’re all there?”

0.5 3 6 … So we say the reals are

“uncountable.”

Counterexample: Use diagonalization

to create a new number that differs in the ith

position of the ith number

by 1.