review for exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · review for...

24
Review for Exam 2 Hyunyoung Lee 1

Upload: others

Post on 28-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Review for Exam 2Hyunyoung Lee

1

Page 2: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Exam Coverage

The exam will cover everything up to now, but the emphasis is on the material that we have covered since the last exam:

- Sequences and Sums

- Proof by induction

- Proof by strong induction

- Inductive Sets

- Recursive Functions

- Proof by structural induction

- Counting

2

Page 3: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Sequences and Sums

3

Page 4: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Geometric SeriesIf a and r �= 0 are real numbers, then

n�

j=0

arj =

�arn+1−a

r−1 if r �= 1

(n+ 1)a if r = 1

Proof:The case r = 1 holds, since arj = a for each of then+ 1 terms of the sum.

The case r �= 1 holds, since

(r − 1)�n

j=0 arj =

n�

j=0

arj+1 −n�

j=0

arj

=n+1�

j=1

arj −n�

j=0

arj

= arn+1 − aand dividing by (r − 1) yields the claim.

Extremely useful!

Page 5: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Sum of First n Positive Integers .

For all n ≥ 1, we haven�

k=1

k = n(n+ 1)/2

We prove this by induction.Basis step: For n = 1, we have

1�

k=1

k = 1 = 1(1 + 1)/2.

Extremely useful!

Page 6: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Sum of the First n Positive Integers

Induction Hypothesis: We assume that the claim

holds for n− 1.

Induction Step: Assuming the Induction Hypoth-

esis, we will show that the claim holds for n.

�nk=1 k = n+

�n−1k=1 k

= 2n/2 + (n− 1)n/2 by Induction Hypothesis

=2n+n2−n

2

=n(n+1)

2

Therefore, the claim follows by induction on n.

Page 7: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Infinite Geometric Series

Let x be a real number such that |x| < 1. Then

∞�

k=0

xk =1

1− x.

Page 8: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Infinite Geometric Series

Since the sum of a geometric series satisfies

n�

k=0

xk =xn+1 − 1

x− 1,

we have

∞�

k=0

xk = limn→∞

n�

k=0

xk = limn→∞

xn+1 − 1

x− 1

As limn→∞ xn+1 = 0, we get

∞�

k=0

xk =−1

x− 1=

1

1− x.

Page 9: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Weak and Strong Induction

9

Page 10: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Motivation

Induction is an axiom which allows us to prove that certain properties are true for all positive integers (or for all nonnegative integers, or all integers >= some fixed number)

10

Page 11: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Induction Principle

Let A(n) be an assertion concerning the integer n.

If we want to show that A(n) holds for all positive integer n, we can proceed as follows:

Induction basis: Show that the assertion A(1) holds.

Induction step: For all positive integers n, show that A(n) implies A(n+1).

11

Page 12: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Strong Induction Principle

Let A(n) be the assertion concerning the integer n.

If we want to prove it for all n >= 1, we can do the following:

Induction basis:

Show that A(1) is true.

Induction step:

Show that (A(1) ⋀... ⋀A(n)) → A(n+1)

holds for all n >=1.12

Page 13: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Weak or Strong Induction?

You might wonder which form of induction you should use.

Generally, you use strong induction when assuming that the assertion A(n) holds does not seem to help in proving A(n+1). Strong induction can make the induction step easier to prove in such cases.

On the other hand, weak induction is sometimes more straightforward to use (so it is preferred when the induction step can be proved by assuming A(n) alone).

13

Page 14: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example

Theorem: For all positive integers n, we have

1+3+5+...+(2n-1) = n2

Proof. We prove this by induction on n. Let A(n) be the assertion of the theorem.

Induction basis: Since 1 = 12, it follows that A(1) holds.

Induction step: Suppose that A(n) holds. Then

1+3+5+...+(2n-1)+(2n+1) = n2+2n+1 = (n+1)2

holds. In other words, A(n) implies A(n+1).

14

Page 15: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Inductively Defined Sets and Structural Induction

15

Page 16: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Inductively Defined Sets

An inductive definition of a set S has the following form:(a) Basis: Specify one or more “initial” elements of S.(b) Induction: Give one or more rules for constructing “new” elements of S from “old” elements of S. (c) Closure: The set S consists of exactly the elements that can be obtained by starting with the initial elements of S and applying the rules for constructing new elements of S.

The closure condition is usually omitted, since it is always assumed in inductive definitions.

16

Page 17: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example

Let S be the set defined as follows:

Basis: 0 ∈ S

Induction: If n ∈ S, then 2n+1 ∈ S.

Can you describe the set S?

S = {0,1,3,7,15,31,... } = { 2n-1 | n a nonnegative integer }

since 20-1=0 and 2n+1-1 = 2(2n-1)+1

17

Page 18: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example: Binary Trees

We can define the set B of binary trees over an alphabet A as follows:

Basis: ⟨⟩∈B. Induction: If L, R∈B and x∈A, then ⟨L,x,R⟩∈B.

Example: ⟨⟨⟩,1,⟨⟩⟩ // tree with one node (1)Example: ⟨ ⟨⟨⟩,1,⟨⟩⟩, r, ⟨⟨⟩,2,⟨⟩⟩ ⟩ // tree with root r and two children (1 and 2).

18

Page 19: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Structural Induction

In structural induction, the proof of the assertion that every element of an inductively defined set S has a certain property P proceeds by showing that

Basis: Every element in the basis of the definition of S satisfies the property P.

Induction: Assuming that every argument of a constructor has property P, show that the constructed element has the property P.

19

Page 20: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example: Binary Trees

Recall that the set B of binary trees over an alphabet A is defined as follows:Basis: ⟨⟩∈B. Induction: If L, R∈B and x∈A, then ⟨L,x,R⟩∈B.

We can now prove that every binary tree has a property P by arguing that Basis: P(⟨⟩) is true.Induction: For all binary trees L and R and x in A, if P(L) and P(R), then P(⟨L,x,R⟩).

20

Page 21: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example: Binary Trees

Let f: B -> N be the function defined by

Theorem: Let T in B be a binary tree. Then f(T) yields the number of leaves of T.

f(��) = 0

f(�L, x,R�) =

�1 if L = R = ��f(L) + f(R) otherwise

21

Page 22: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example: Binary Trees

Theorem: Let T in B be a binary tree. Then f(T) yields the number of leaves of T.

Proof: By structural induction on T.

Basis: The empty tree has no leaves, so f(⟨⟩) = 0 is correct.

Induction: Let L,R be trees in B, x in A.

Suppose that f(L) and f(R) denotes the number of leaves of L and R, respectively.

If L=R=⟨⟩, then ⟨L,x,R> = ⟨⟨⟩,x,⟨⟩⟩ has one leaf, namely x, so f(⟨⟨⟩,x,⟨⟩⟩)=1 is correct.

22

Page 23: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Example: Binary Trees

If L and R are not both empty, then the number of leaves of the tree ⟨L,x,R⟩ is equal to the number of leaves of L plus the number of leaves of R. Hence, by induction hypothesis, we get

f(⟨L,x,R⟩) = f(R)+f(L)

as claimed.

This completes the proof.

23

Page 24: Review for Exam 2 - ecology labfaculty.cse.tamu.edu/hlee/csce222/review-for-exam2.pdf · Review for Exam 2 Hyunyoung Lee 1. Exam Coverage The exam will cover everything up to now,

Counting

- Product rule

- Sum rule

- Subtraction rule

- Generalized Pigeonhole principle

- Counting in two different ways (double counting)

- Permutations

- Combinations

- Binomial theorem

- Binomial coefficient identities, counting subset identity

- Pascal’s identity24