2015 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 귀납과 재귀 (Induction and Recursion)

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Induction and Recursion Spring 2014 Sukumar Ghosh.
Advertisements

22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
10.1 CompSci 102© Michael Frank Today’s topics RecursionRecursion –Recursively defined functions –Recursively defined sets –Structural Induction Reading:
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Recursion Rosen 5 th ed., § Recursion Sometimes, defining an object explicitly might be difficult.Sometimes, defining an object explicitly might.
CSE115/ENGR160 Discrete Mathematics 04/05/11 Ming-Hsuan Yang UC Merced 1.
1 Inductive Proofs Rosen 6 th ed., § Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every.
Recursion. Recursive Definitions In recursive definitions, we define a function, a predicate, a set, or a more complex structure over an infinite domain.
Section Section Summary Recursive Algorithms Proving Recursive Algorithms Correct Recursion and Iteration (not yet included in overheads) Merge.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen Induction.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.
Induction and recursion
Discrete Mathematics Chapter 4 Induction and Recursion 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Mathematical Maxims and Minims, 1988
2015 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수열과 합 (Sequences and Summations)
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 4 Induction and Recursion 歐亞書局.
Chapter 4: Induction and Recursion
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)
INDUCTION AND RECURSION. PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function,
Module #14: Recursion Rosen 5 th ed., §§ In this class, we will study recursion, one of the most important topics in computer science. In the last.
이산수학 (Discrete Mathematics) 3.5 재귀 알고리즘 (Recursive Algorithms) 2006 년 봄학기 문양세 강원대학교 컴퓨터과학과.
Module #13: Inductive Proofs Rosen 5 th ed., § inference of a generalized conclusion from particular instances 2. mathematical demonstration of the.
Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.
Chapter 5 With Question/Answer Animations. Section 5.1.
강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수열과 합 (Sequences and Summations)
Chap 3 –A theorem is a statement that can be shown to be true –A proof is a sequence of statements to show that a theorem is true –Axioms: statements which.
2014 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics)  집합 (Set)
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
1 Inductive Proofs Rosen 6 th ed., § Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Module #15 – Inductive Proofs 12/6/2015(c) , Michael P. Frank1 Inductive Proofs: a brief introduction Rosen 5 th ed., §3.3 ~35 slides, ~1.5 lecture.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
2014 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수열과 합 (Sequences and Summations)
Inductive Proofs and Inductive Definitions Jim Skon.
Recursive Algorithm (4.4) An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with smaller input.
2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수학적 귀납법 (Mathematical Induction)
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
3.3 Mathematical Induction 1 Follow me for a walk through...
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Chapter 4: Induction and Recursion
Recursive Algorithms Section 5.4.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Induction and Recursion
Mathematical Induction Recursion
Chapter 5 Induction and Recursion
Discrete Mathematics and its Applications
Rosen 5th ed., §§ ~18 slides, ~1 lecture
Applied Discrete Mathematics Week 9: Integer Properties
Module #13: Inductive Proofs
Rosen 5th ed., §§ ~18 slides, ~1 lecture
Mathematical Induction
Discrete Mathematics and its Applications
Discrete Mathematics and its Applications
Induction and recursion
Discrete Mathematics and its Applications
Recursion.
Presentation transcript:

2015 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 귀납과 재귀 (Induction and Recursion)

Discrete Mathematics by Yang-Sae Moon Page 2 강의 내용 수학적 귀납법 (Mathematical Inductions) 재귀 (Recursion) 재귀 알고리즘 (Recursive Algorithms) Induction and Recursion

Discrete Mathematics by Yang-Sae Moon Page 3 Introduction Mathematical Induction A powerful technique for proving that a predicate P(n) is true for every natural number n, no matter how large. ( 모든 자연수 n 에 대해서 P(n) 이 true 임을 보일 수 있는 매우 유용한 방법임 ) Essentially a “domino effect” principle. ( 앞에 것이 성립하면 ( 넘어지면 ), 바로 다음 것도 성립한다 ( 넘어진다.) Based on a predicate-logic inference rule: P(0)  n  0 (P(n)  P(n+1))  n  0 P(n) P(0) 가 true 이고, P(n) 이 true 라 가정했을 때 P(n+1) 이 true 이면, 모든 n 에 대해 P(n) 이 true 이다.

Discrete Mathematics by Yang-Sae Moon Page 4 Validity of Induction Intuitively, we can prove that induction is correct. P(1) = T since (P(0) = T)  (P(0)  P(1) = T) P(2) = T since (P(1) = T)  (P(1)  P(2) = T) P(3) = T since (P(2) = T)  (P(2)  P(3) = T) … P(n) = T since (P(n-1) = T)  (P(n-1)  P(n) = T) Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 5 Outline of an Inductive Proof Want to prove  n P(n)… Induction basis (or base case): Prove P(0). ( 기본 단계 ) Induction step: Prove  n P(n)  P(n+1). ( 귀납적 단계 ) -E.g. use a direct proof: -Let n  N, assume P(n). (induction hypothesis) -Under this assumption, prove P(n+1). Inductive inference rule then gives  n P(n). Can also be used to prove  n  c P(n) for a given constant c  Z, where maybe c  0. (Base 로 0 이 아닌 상수 c 를 사용할 수 있다.) In this circumstance, the base case is to prove P(c) rather than P(0), and the inductive step is to prove  n  c (P(n)  P(n+1)). Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 6 Induction Examples (1/4) Prove that the sum of the first n odd positive integers is n 2. That is, prove: ( 처음 n 개 홀수의 합은 n 2 와 동일하다.) Proof by Induction Induction basis: Let n=1. Since 1 = 1 2, P(1) is true. Induction step: Let n  1, assume P(n), and prove P(n+1). P(n)P(n) By induction hypothesis P(n) Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 7 Induction Examples (2/4) Prove that  n>0, n<2 n. Let P(n)=(n<2 n ) : Induction basis: P(1) = (1 < 2 1 ) = (1 < 2) = T. Induction step: For n>0, prove P(n)  P(n+1). -Assuming n<2 n, prove n+1 < 2 n+1. -Note n + 1 < 2 n + 1 (by inductive hypothesis) < 2 n + 2 n (because 1 < 2=2∙2 0  2∙2 n-1 = 2 n ) = 2 n+1 -So n + 1 < 2 n+1, and we’re done. Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 8 Induction Examples (3/4) Prove that the sum of the first n positive integers is n(n+1)/2. Let P(n) = Induction basis: Let P(1) = Induction step: Let n  1, assume P(n), and prove P(n+1). Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 9 Induction Examples (4/4) Prove when n  2. Induction basis: n = 2, Induction step: Assume P(n), and prove P(n+1). Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 10 Second Principle of Induction ( 강 귀납법 ) Characterized by another inference rule: P(0)  n  0: (  0  k  n P(k))  P(n+1)  n  0: P(n) Difference with 1 st principle is that the inductive step uses the fact that P(k) is true for all smaller k<n+1, not just for k=n. (Induction step 에서 k=n 인 경우 대신에, k<n+1 인 모든 k 에 대해 P(k) 가 true 라 가정한다.) P(0) 가 true 이고, P(0),…,P(n) 이 모두 true 라 가정했을 때 P(n+1) 이 true 이면, 모든 n 에 대해 P(n) 이 true 이다. Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 11 Example of Second Principle Show that every n>1 can be written as a product p 1 p 2 …p s of some series of s prime numbers. Let P(n)=“n has that property” ( 모든 양의 정수는 소수의 곱으로 나타낼 수 있다.) Induction basis: n=2, let s=1, p 1 =2. Thus, P(2) = T. Induction step: Let n  2. Assume 2  k  n: P(k). -Consider n+1. If prime, let s=1, p 1 =n+1. Done. -Else n+1=ab, where 1<a  n and 1<b  n. -Then a=p 1 p 2 …p t and b=q 1 q 2 …q u. -Then n+1= p 1 p 2 …p t q 1 q 2 …q u, a product of s=t+u primes. Mathematical Induction

Discrete Mathematics by Yang-Sae Moon Page 12 강의 내용 수학적 귀납법 (Mathematical Inductions) 재귀 (Recursion) 재귀 알고리즘 (Recursive Algorithms) Induction and Recursion

Discrete Mathematics by Yang-Sae Moon Page 13 Recursive Definitions ( 재귀의 정의 ) Recursion In induction, we prove all members of an infinite set have some property P by proving the truth for larger members in terms of that of smaller members. ( 귀납적 정의에서는, “ 무한 집합의 모든 멤버가 어떠한 성질 P 를 가짐 ” 을 보이기 위하여, “ 작은 멤버들을 사용하여 큰 멤버들이 참 (P 의 성질을 가짐 ) 임 ” 을 증명하 는 방법을 사용하였다.) In recursive definitions, we similarly define a function, a predicate or a set over an infinite number of elements by defining the function or predicate value or set-membership of larger elements in terms of that of smaller ones. ( 재귀적 정의에서는, “ 작은 멤버들에 함수 / 술어 / 집합을 적용 ( 정의 ) 하여 모든 멤 버들을 정의 ” 하는 방법을 사용한다.)

Discrete Mathematics by Yang-Sae Moon Page 14 Recursion ( 재귀 ) Recursion is a general term for the practice of defining an object in terms of itself (or of part of itself). ( 재귀란 객체를 정의하는데 있어서 해당 객체 자신을 사용하는 것을 의미한다.) An inductive proof establishes the truth of P(n+1) recursively in terms of P(n). ( 귀납적 증명은 P(n+1) 이 참임을 증명하기 위하여 재귀적으로 P(n) 을 사용하는 것으로 해석할 수 있다.) There are also recursive algorithms, definitions, functions, sequences, and sets. Recursion

Discrete Mathematics by Yang-Sae Moon Page 15 Recursively Defined Functions Simplest case: One way to define a function f:N  S (for any set S) or series a n =f(n) is to: Define f(0). For n>0, define f(n) in terms of f(0),…,f(n−1). E.g.: Define the series a n : ≡ 2 n recursively: Let a 0 : ≡ 1. For n>0, let a n : ≡ 2a n-1. Recursion

Discrete Mathematics by Yang-Sae Moon Page 16 Another Example Suppose we define f(n) for all n  N recursively by: Let f(0)=3 For all n  N, let f(n+1)=2f(n)+3 What are the values of the following? f(1)= f(2)= f(3)= f(4)= Recursion

Discrete Mathematics by Yang-Sae Moon Page 17 Recursive Definition of Factorial Given an inductive definition of the factorial function F(n) : ≡ n! : ≡ 2  3  …  n. Base case: F(0) : ≡ 1 Recursive part: F(n) : ≡ n  F(n-1). −F(1)=1 −F(2)=2 −F(3)=6 Recursion

Discrete Mathematics by Yang-Sae Moon Page 18 The Fibonacci Series The Fibonacci series f n≥0 is a famous series defined by: f 0 : ≡ 0, f 1 : ≡ 1, f n≥2 : ≡ f n−1 + f n− Recursion

Discrete Mathematics by Yang-Sae Moon Page 19 Inductive Proof about Fibonacci Series Theorem: f n < 2 n. Proof: By induction. Base cases:f 0 = 0 < 2 0 = 1 f 1 = 1 < 2 1 = 2Base cases:f 0 = 0 < 2 0 = 1 f 1 = 1 < 2 1 = 2 Inductive step: Use 2 nd principle of induction (strong induction). Assume  k<n, f k < 2 k. Then f n = f n−1 + f n−2 is < 2 n−1 + 2 n−2 < 2 n−1 + 2 n−1 = 2 n. Inductive step: Use 2 nd principle of induction (strong induction). Assume  k<n, f k < 2 k. Then f n = f n−1 + f n−2 is < 2 n−1 + 2 n−2 < 2 n−1 + 2 n−1 = 2 n.  Recursion

Discrete Mathematics by Yang-Sae Moon Page 20 Recursively Defined Sets An infinite set S may be defined recursively, by giving: A small finite set of base elements of S. ( 유한 개수의 기본 원소를 제시 ) A rule for constructing new elements of S from previously- established elements. ( 새로운 원소를 만드는 방법을 제시 ) Example: Let 3  S, and let x+y  S if x,y  S. What is S? (= {3, 6, 9, 12, 15, …}) Recursion

Discrete Mathematics by Yang-Sae Moon Page 21 강의 내용 수학적 귀납법 (Mathematical Inductions) 재귀 (Recursion) 재귀 알고리즘 (Recursive Algorithms) Induction and Recursion

Discrete Mathematics by Yang-Sae Moon Page 22 Introduction Recursive Algorithms Recursive definitions can be used to describe algorithms as well as functions and sets. ( 재귀적 정의를 수행한 경우, 손쉽게 알고리즘의 함수 / 집합으로 기술할 수 있다.) 예제 : A procedure to compute a n. procedure power(a≠0: real, n  N) if n = 0 then return 1 else return a · power(a, n−1)

Discrete Mathematics by Yang-Sae Moon Page 23 Efficiency of Recursive Algorithms The time complexity of a recursive algorithm may depend critically on the number of recursive calls it makes. ( 재귀 호출에서의 시간 복잡도는 재귀 호출 횟수에 크게 의존적이다.) 예제 : Modular exponentiation to a power n can take log(n) time if done right, but linear time if done slightly differently. ( 잘하면 O(log(n)) 이나, 조금만 잘못하면 O(n) 이 된다.) Task: Compute b n mod m, where m≥2, n≥0, and 1≤b<m. Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 24 Modular Exponentiation Algorithm #1 Uses the fact that b n = b·b n−1 and that x·y mod m = x·(y mod m) mod m. Note this algorithm takes  (n) steps! procedure mpower(b≥1,n≥0,m>b  N) {Returns b n mod m.} if n=0 then return 1; else return (b·mpower(b,n−1,m)) mod m; Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 25 Modular Exponentiation Algorithm #2 Uses the fact that b 2k = b k·2 = (b k ) 2, x·y mod m = x·(y mod m) mod m, and x·x mod m = (x mod m) 2 mod m. What is its time complexity? procedure mpower(b,n,m) {same signature} if n=0 then return 1 else if 2|n then return mpower(b,n/2,m) 2 mod m else return (mpower(b,n−1,m)·b) mod m ( 첫 번째 mpower() 는 한번 call 되고, 그 값을 제곱하는 것임 )  (log n) steps Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 26 A Slight Variation of Algorithm #2 Nearly identical but takes  (n) time instead! The number of recursive calls made is critical. procedure mpower(b,n,m) {same signature} if n=0 then return 1 else if 2|n then return (mpower(b,n/2,m)·mpower(b,n/2,m)) mod m else return (mpower(b,n−1,m)·b) mod m Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 27 Recursive Euclid’s Algorithm ( 예제 ) Note recursive algorithms are often simpler to code than iterative ones… (Recursion 이 코드를 보다 간단하게 하지만 …) However, they can consume more stack space, if your compiler is not smart enough. ( 일반적으로, recursion 은 보다 많은 stack space 를 차지한다.) procedure gcd(a,b  N) if a = 0 then return b else return gcd(b mod a, a) Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 28 Recursion vs. Iteration (1/3) Factorial – Recursion procedure factorial(n  N) if n = 1 then return 1 else return n  factorial(n – 1) Factorial – Iteration procedure factorial(n  N) x := 1 for i := 1 to n x := i  x return x Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 29 Recursion vs. Iteration (2/3) Fibonacci – Recursion procedure fibonacci(n: nonnegative integer) if (n = 0 or n = 1) then return n else return (fibonacci(n–1) + fibonacci(n–2)) Fibonacci – Iteration procedure fibonacci(n: nonnegative integer) if n = 0 then return 0 else x := 0, y := 1 for i := 1 to n – 1 z := x + y, x := y, y := z return z Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 30 재귀 (recursion) 는 프로그램을 간단히 하고, 이해하기가 쉬 운 장점이 있는 반면에, 각 호출이 스택을 사용하므로, depth 가 너무 깊어지지 않도 록 조심스럽게 프로그래밍해야 함 컴퓨터에게 보다 적합한 방법은 반복 (iteration) 을 사용한 프 로그래밍이나, 적당한 범위에서 재귀를 사용하는 것이 바람 직함 Recursion vs. Iteration (3/3) Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 31 Merge Sort ( 예제 ) (1/2) The merge takes (n) steps, and merge-sort takes (n log n). The merge takes  (n) steps, and merge-sort takes  (n log n). procedure sort(L = 1,…, n ) if n>1 then m :=  n/2  {this is rough ½-way point} L := merge(sort( 1,…, m ), sort( m+1,…, n )) return L Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 32 The Merge Routine procedure merge(A, B: sorted lists) L = empty list i:=0, j:=0, k:=0 while i<|A|  j<|B| {|A| is length of A} if i=|A| then L k := B j ; j := j + 1 else if j=|B| then L k := A i ; i := i + 1 else if A i < B j then L k := A i ; i := i + 1 else L k := B j ; j := j + 1 k := k+1 return L Merge Sort ( 예제 ) (2/2) – skip Recursive Algorithms

Discrete Mathematics by Yang-Sae Moon Page 33 강의 내용 수학적 귀납법 (Mathematical Inductions) 재귀 (Recursion) 재귀 알고리즘 (Recursive Algorithms) Induction and Recursion

Discrete Mathematics by Yang-Sae Moon Page 34 Homework #5 Recursive Algorithms