### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# FoCS Exam #1 Study Guide CSCI 2200

RPI

### View Full Document

## 174

## 2

## Popular in Foundations of Computer Science

## Popular in ComputerScienence

This 34 page Study Guide was uploaded by thersh on Monday February 29, 2016. The Study Guide belongs to CSCI 2200 at Rensselaer Polytechnic Institute taught by Petros Drineas in Spring 2016. Since its upload, it has received 174 views. For similar materials see Foundations of Computer Science in ComputerScienence at Rensselaer Polytechnic Institute.

## Reviews for FoCS Exam #1 Study Guide

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/29/16

Induction and recursion Climbing an Infinite Ladder Suppose we have an infinite ladder: 1. We can reach the first rung of the ladder. 2. If we can reach a particular rung of the ladder, then we can reach the next rung. From (1), we can reach the first rung. Then by applying (2), we can reach the second rung. Applying (2) again, the third rung. And so on. We can apply (2) any number of times to reach any particular rung, no matter how high up. This example motivates proof by mathematical induction. Principle of Mathematical Induction positive integers n, we complete these steps:e that P(n) is true for all • Basis Step: Show that P(1) is true. • Inductive Step: Show that P(k) → P(k + 1) is true for all positive integers k. To complete the inductive step, assuming the inductive hypothesis that P(k) holds for an arbitrary integer k, show that must P(k + 1) be true. Climbing an Infinite Ladder Example: • BASIS STEP: By (1), we can reach rung 1. • INDUCTIVE STEP: Assume the inductive hypothesis that we can reach rung k. Then by (2), we can reach rung k + 1. Hence, P(k) → P(k + 1) is true for all positive integers k. We can reach every rung on the ladder. Important Points About Using Mathematical Induction •In a proof by mathematical induction, we don’t assume that P(k) is true for all positive integers! We show that if we assume that P(k) is true, then P(k + 1) must also be true. •Proofs by mathematical induction do not always start at the integer 1. In such a case, the basis step begins at a starting point b where b is an inte.er We will see examples of this soon. Remembering How Mathematical Induction Works Consider an infinite We know that the first domino is sequence of dominoes, knocked down, i.e., P(1) is true . labeled 1,2,3, …, where each domino is standing. We also know that if whenever the kth domino is knocked over, it Let P(n) be the knocks over the (k + 1)st domino, proposition that the i.e, P(k) → P(k + 1) is true for all nth domino is positive integers k. knocked over. Hence, all dominos are knocked over. P(n) is true for all positive integers n. Proving a Summation Formula by Mathematical Induction Example: Show that: Note: Once we have this i conjecture, mathematical Solution: induction can be used to • BASIS STEP: P(1) is true since 1(1 + 1)/2 = 1. prove it correct. • INDUCTIVE STEP: Assume true for P(k). The inductive hypothesis is Under this assumption, i Conjecturing and Proving Correct a Summation Formula Example: Conjecture and prove correct a formula for the sum of the first n positive odd integers. Then prove your conjecture. Solution: We have: 1= 1, 1 + 3 = 4, 1 + 3 + 5 = 9, 1 + 3 + 5 + 7 = 16, 1 + 3 + 5 + 7 + 9 = 25. • We can conjecturethat the sum of the first n positiveodd integersis n , 2 • We prove the conjectureis proved correct with mathematicalinduction. • BASIS STEP: P(1) is true since 1 = 1. • INDUCTIVESTEP: P(k) → P(k + 1) for every positiveinteger k. Assume the inductive hypothesis holds and then show that P(k) holds has well. InductiveHypothesis:1 + 3 + 5 + ∙∙∙+ (2k − 1) =k 2 • So, assumingP(k), it followsthat: 1 + 3 + 5 + ∙∙∙+ (2k − 1) + (2k + 1) =[1 + 3 + 5 + ∙∙∙+ (2k − 1)] + (2k + 1) = k + (2k + 1) (by the inductivehypothesis) = k + 2k + 1 2 = (k + 1) • Hence, we have shown that P(k + 1) followsfrom P(k). Therefore the sum of the first n positiveodd integers is n . Proving Inequalities n Example: Use mathematical induction to prove that n < 2 for all positive integers n. Solution: Let P(n) be the proposition that n < 2 . n • BASIS STEP: P(1) is true since 1 < 2 = 2. k • INDUCTIVE STEP: Assume P(k) holds, i.e., k < 2 , for an arbitrary positive integer k. • Must show that P(k + 1) holds. Since by the inductive hypothesis, k < 2 , it follows that: k + 1 < 2 + 1 ≤ 2 + 2 = 2 ∙ 2 = 2 k+1 n Therefore n < 2 holds for all positive integers n. Proving Inequalities Example: Use mathematical induction to prove that 2 < n!, for every integer n ≥ 4. Solution: Let P(n) be the proposition that 2 < n!. n • BASIS STEP: P(4) is true since 2 = 16 < 4! = 24. k • INDUCTIVE STEP: Assume P(k) holds, i.e., 2 < k! for an arbitrary integer k ≥ 4. To show that P(k + 1) holds: 2 k+1= 2∙2k < 2∙ k! (by the inductive hypothesis) < (k + 1)k! = (k + 1)! n Therefore, 2 < n! holds, for every integer n ≥ 4. Note that here the basis step is P(4), since P(0), P(1), P(2), and P(3) are all false. Proving Divisibility Results Example: Use mathematical induction to prove that n − n is divisible by 3, for every positive integer n. Solution: Let P(n) be the proposition that n − n is divisible by 3. 3 • BASIS STEP: P(1) is true since 1 − 1 = 0, which is divisible by 3. • INDUCTIVE STEP: Assume P(k) holds, i.e., k − k is divisible by 3, for an arbitrary positive integer k.To show that P(k + 1) follows: (k + 1) − (k + 1) = (k + 3k + 3k+ 1) − (k + 1) = (k − k) + 3(k + k) 3 By the inductive hypothesis, the first term (k − k) is divisible by 3 and the second term is divisible by 3 since it is an integer multiplied by 3. So, (k + 1) − (k + 1) is divisible by 3. 3 Therefore, n − n is divisible by 3, for every integer positive integer n. Number of Subsets of a Finite Set Example: Use mathematical induction to show that if S is a finite sen with n elements, where n is a nonnegative integer, then S has 2 subsets. Solution: Let P(n) be the proposition that a set with n elements has 2 n subsets. • B0sis Step: P(0) is true, because the empty set has only itself as a subset and 2 = 1. • Inductive Step: Assume P(k) is true for an arbitrary nonnegative integer k. continued → Number of Subsets of a Finite Set Inductive Hypothesis: For an arbitrary nonnegative integer k, every set with k elements has 2 subsets. • Let T be a set with k + 1 elements. Then T = S ∪ {a}, where a ∈ T and S = T − {a}. Hence |S| = k. • For each subset X of S, there are exactly two subsets of T, i.e., X and X ∪ {a}. • By the inductive hypothesis S has 2 subsets. Since there are two subsets of T for each subset of S, the number of subsets of T is 2∙2 = 2 k+1. An Incorrect “Proof” by Mathematical Induction Example: Let P(n) be the statement that every set of n lines in the plane, no two of which are parallel, meet in a common point. Here is a “proof” that P(n) is true for all positive integers n ≥ 2. • BASIS STEP: The statement P(2) is true because any two lines in the plane that are not parallel meet in a common point. • INDUCTIVE STEP: The inductive hypothesis is the statement that P(k) is true for the positive integer k ≥ 2, i.e., every set of k lines in the plane, no two of which are parallel, meet in a common point. • We must show that if P(k) holds, then P(k + 1) holds, i.e., if every set of k lines in the plane, no two of which are parallel, k ≥ 2, meet in a common point, then every set of k + 1 lines in the plane, no two of which are parallel, meet in a common point. continued → An Incorrect “Proof” by Mathematical Induction Inductive Hypothesis: Every set of k lines in the plane, where k ≥ 2, no two of which are parallel, meet in a common point. • Consider a set of k + 1 distinct lines in the plane, no two parallel. By the inductive hypothesis, the first k of these lines must meet in a common point p . By the inductive hypothesis, the last k of these lines meet in a common point p . 2 • If 1 and p 2re different points, all lines containing both of them must be the same line since two points determine a line. This contradicts the assumption that the lines are distinct. Hence, p 1 p 2 lies on all k + 1 distinct lines, and therefore P(k + 1) holds. Assuming that k ≥2, distinct lines meet in a common point, then every k + 1 lines meet in a common point. • There must be an error in this proof since the conclusion is absurd. But where is the error? • Answer: P(k)→ P(k + 1) only holds for k ≥3. It is not the case that P(2) implies P(3). The first two lines must meet in a common po1nt p and the second two must meet in a common point p2. They do not have to be the same point since only the second line is common to both sets of lines. Guidelines: Mathematical Induction Proofs Strong Induction • Strong Induction: To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, complete two steps: • Basis Step: Verify that the proposition P(1) is true. • Inductive Step: Show the conditional statement [P(1) ∧ P(2) ∧∙∙∙ ∧ P(k)] → P(k + 1) holds for all positive integers k. Strong Induction is sometimes called the second principle of mathematical induction or complete induction. Strong Induction and the Infinite Ladder Strong induction tells us that we can reach all rungs if: 1. We can reach the first rung of the ladder. 2. For every integer k, if we can reach the first k rungs, then we can reach the (k + 1)st rung. To conclude that we can reach every rung by strong induction: • BASIS STEP: P(1) holds • INDUCTIVE STEP: Assume P(1) ∧ P(2) ∧∙∙∙ ∧ P(k) holds for an arbitrary integer k, and show that P(k + 1) must also hold. We will have then shown by strong induction that for every positive integer n, P(n) holds, i.e., we can reach the nth rung of the ladder. Which Form of Induction Should Be Used? • We can always use strong induction instead of mathematical induction. But there is no reason to use it if it is simpler to use mathematical induction. • In fact, the principles of mathematical induction, strong induction, and the well-ordering property are all equivalent. • Sometimes it is clear how to proceed using one of the three methods, but not the other two. Proof using Strong Induction Example: Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps. Solution: Let P(n) be the proposition that postage of n cents can be formed using 4-cent and 5-cent stamps. • BASIS STEP: P(12), P(13), P(14), and P(15) hold. • P(12) uses three 4-cent stamps. • P(13) uses two 4-cent stamps and one 5-cent stamp. • P(14) uses one 4-cent stamp and two 5-cent stamps. • P(15) uses three 5-cent stamps. • INDUCTIVE STEP: The inductive hypothesis states that P(j) holds for 12 ≤ j ≤ k, where k ≥ 15. Assuming the inductive hypothesis, it can be shown that P(k + 1) holds. • Using the inductive hypothesis, P(k − 3) holds since k − 3 ≥ 12. To form postage of k + 1 cents, add a 4-cent stamp to the postage for k − 3 cents. Hence, P(n) holds for all n ≥ 12. Proof of Same Example using Mathematical Induction Example: Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps. Solution: Let P(n) be the proposition that postage of n cents can be formed using 4-cent and 5-cent stamps. • BASIS STEP: Postage of 12 cents can be formed using three 4-cent stamps. • INDUCTIVE STEP: The inductive hypothesis P(k) for any positive integer k is that postage of k cents can be formed using 4-cent and 5-cent stamps. To show P(k + 1) where k ≥ 12 , we consider two cases: • If at least one 4-cent stamp has been used, then a 4-cent stamp can be replaced with a 5-cent stamp to yield a total of k + 1 cents. •used. Three 5-cent stamps can be replaced by four 4-cent stamps to yield a total of k + 1 cents. Hence, P(n) holds for all n ≥ 12. Recursively Defined Functions Definition: A recursive or inductive definition of a function consists of two steps. • BASIS STEP: Specify the value of the function at zero. • RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers. • A function f(n) is the same as a sequence a , a , …0, w1ere a, where i f(i) = i. This was done using recurrence relations in Section 2.4. Recursively Defined Functions Example: Suppose f is defined by: f(0) = 3, f(n + 1) = 2f(n) + 3 Find f(1), f(2), f(3), f(4) Solution: • f(1) = 2f(0) + 3 = 2∙3 + 3 = 9 • f(2) = 2f(1)+ 3 = 2∙9 + 3 = 21 • f(3) = 2f(2) + 3 = 2∙21 + 3 = 45 • f(4) = 2f(3) + 3 = 2∙45 + 3 = 93 Example: Give a recursive definition of the factorial function n!: Solution: f(0) = 1 f(n + 1) = (n + 1)∙ f(n) Recursively Defined Functions Example: Give a recursive definition of: Solution: The first part of the definition is The second part is Fibonacci Fibonacci Numbers (1170- 1250) Example : The Fibonacci numbers are defined as follows: f0= 0 f = 1 1 fn= fn−1 + fn−2 Find f , f , f , f . 2 3 4 5 • f2= f1 + f0= 1 + 0 = 1 • f3= f2+ f 1 1 + 1 = 2 • f4= f3+ f2= 2 + 1 = 3 • f5= f4+ f3= 3 + 2 = 5 Fibonacci Numbers Example 4: Show that whenever n ≥ 3, f > α n − 2, where α = (1 + √5)/2. n Solution: Let P(n) be the statement f > α n−2 . Use strong induction to show n that P(n) is true whenever n ≥ 3. • BASIS STEP: P(3) holds since α < 2 = f 2 3 P(4) holds since α = (3 + √5)/2 < 3 = f . 4 • INDUCTIVE STEP: Assume that P(j) holds, i.e., f > j j−2for all integers j with k−1 3 ≤ j ≤ k, where k ≥ 4. Show that P(k + 1) holds, i.e., f k+1> α . • Sink−1α = α2+ 1 k−3cause α is a sok−3ion of xk−3x − 1 =k−3, k−2 k−3 α = α ∙ α = ( α + 1)∙α = α∙α + 1∙α = α + α Why does this • By the induk−1v> αypot,esis, fk> αse k . 4 we have equality hold? k−2 k−3 k−1 • Therefore, fk+1= f k fhak−1 > α + α = α . − 2 . • Hence, P(k + 1) is true. Building Up Full Binary Trees Structural Induction Definition: To prove a property of the elements of a recursively defined set, we use structural induction. BASIS STEP: Show that the result holds for all elements specified in the basis step of the recursive definition. RECURSIVE STEP: Show that if the statement is true for each of the elements used to construct new elements in the recursive step of the definition, the result holds for these new elements. • The validity of structural induction can be shown to follow from the principle of mathematical induction. Full Binary Trees Definition: The height h(T) of a full binary tree T is defined recursively as follows: • BASIS STEP: The height of a full binary tree T consisting of only a root r is h(T) = 0. • RECURSIVE STEP: If T a1d T ar2 full binary trees, then the full binary tree T = T1∙T2has height h(T) = 1 + max(h(T 1,h(T 2). • The number of vertices n(T) of a full binary tree T satisfies the following recursive formula: • BASIS STEP: The number of vertices of a full binary tree T consisting of only a root r is n(T) = 1. • RECURSIVE STEP: If T a1d T are2full binary trees, then the full binary tree T = T ∙T has the number of vertices n(T) = 1 + n(T ) + n(T ). 1 2 Structural Induction and Binary Trees Theorem: If T is a full binary tree, then n(T) ≤ 2 h(T)+1 – 1. Proof: Use structural induction. • BASIS STEP: The result holds for a full binary tree consisting only of a root, n(T) = 1 and h(T) = 0. Hence, n(T) = 1 ≤ 2 0+1– 1 = 1. • RECURSIVE STEP: Assume n(T ) ≤ 2 h(1 )+– 1 and also n(T ) ≤ 2h(2 )+1– 1 whenever T and T are full binary trees. 2 1 2 n(T) = 1 + n(T ) + n(T ) (by recursive formula of n(T)) 1 2 ≤ 1 + (2h(T1)+– 1) + (2 h(T2)+– 1) (by inductive hypothesis) ≤ 2∙max(2 h(T1)+,2h(T2)+1)– 1 = 2∙2max(h(T1),h(T2)– 1 (max(2 , 2 )= 2 max(x,y) h(T) = 2∙2 – 1 (by recursive definition of h(T)) = 2h(T)+1– 1 − 2 . Generalized Induction Example: Suppose that a m,n is defined for (m,n)∊N ×N by a = 0 and 0,0 Show that a m,n = m + n(n + 1)/2 is defined for all (m,n)∊N ×N. Solution: Use generalized induction. BASIS STEP: a = 0 = 0 + (0∙1)/2 0,0 INDUCTIVE STEP: Assume that a m̍,n̍m+ ̍ n(̍ n̍ + 1)/2 whenever(m̍,n̍) is less than (k,h) in the lexicographic ordering of N ×N . • If h = 0, by the inductive hypothesis we can conclude ak,h ak−1,h 1 = k − 1+ h(h + 1)/2 + 1 = k + h(h + 1)/2 . • If h > 0, by the inductive hypothesis we can conclude ak,ha k,h-1h = k + h(h − 1)/2 +h = k + h(h + 1)/2 . − 2 . Recursive Algorithms Definition: An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with smaller input. • For the algorithm to terminate, the instance of the problem must eventually be reduced to some initial case for which the solution is known. Recursive Factorial Algorithm Example: Give a recursive algorithm for computing n!, where n is a nonnegative integer. • Solution: Use the recursive definition of the factorial function. procedure factorial(n: nonnegative integer) if n = 0 thenreturn1 else returnn∙factorial(n − 1) {output is n!} Recursive Exponentiation Algorithm n Example: Give a recursive algorithm for computing a , where a is a nonzero real number and n is a nonnegative integer. Solution: Use the recursive definition afn. procedure power(a: nonzero real number, n: nonnegative integer) if n = 0 thenreturn1 else returna∙ power (a, n − 1) n {output is a } Proving Recursive Algorithms Correct • Both mathematical and str0ng induction are useful techniques to show that recursive algorithms always produce the correct output. Example: Prove that the algorithm for computing the powers of real numbers is correct. procedurepower(a: nonzero real number, n: nonnegative integer) if n = 0 thenreturn1 else returna∙ power (a, n − 1) {output is a } Solution: Use mat0ematical induction on the exponent n. BASIS STEP: a =1 for every nonzero real number a, and power(a,0) = 1. INDUCTIVE STEP: The inductive hypothesis is that powerk+1k) = a , for all a ≠0. Assuming the inductive hypothesis, the algorithm correctly computes a , since power(a,k + 1) = a∙ power (a, k) = a∙ a = a k+1. − 2 .

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

#### "I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.