Presentation is loading. Please wait.

Presentation is loading. Please wait.

강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)

Similar presentations


Presentation on theme: "강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)"— Presentation transcript:

1 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)

2 Discrete Mathematics by Yang-Sae Moon Page 2 Recursive Definitions ( 재귀의 정의 ) 3.4 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. ( 재귀적 정의에서는, “ 작은 멤버들에 함수 / 술어 / 집합을 적용 ( 정의 ) 하여 모든 멤 버들을 정의 ” 하는 방법을 사용한다.)

3 Discrete Mathematics by Yang-Sae Moon Page 3 Recursion ( 재귀 ) 3.4 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.

4 Discrete Mathematics by Yang-Sae Moon Page 4 Recursively Defined Functions 3.4 Recursion 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.

5 Discrete Mathematics by Yang-Sae Moon Page 5 Another Example 3.4 Recursion 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)= 9 21 4593

6 Discrete Mathematics by Yang-Sae Moon Page 6 Recursive Definition of Factorial 3.4 Recursion 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

7 Discrete Mathematics by Yang-Sae Moon Page 7 The Fibonacci Series 3.4 Recursion 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−2 0 11 23 58 13

8 Discrete Mathematics by Yang-Sae Moon Page 8 Inductive Proof about Fibonacci Series 3.4 Recursion 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. 

9 Discrete Mathematics by Yang-Sae Moon Page 9 Recursively Defined Sets 3.4 Recursion 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, …})

10 Discrete Mathematics by Yang-Sae Moon Page 10 The Set of All Strings – skip 3.4 Recursion Given an alphabet , the set  * of all strings over  can be recursively defined as:    * (  : ≡ “”, the empty string) w   *  x   → wx   *

11 Discrete Mathematics by Yang-Sae Moon Page 11 Useful Information 3.4 Recursion I will not handle “structural induction,” and thus, you may skip pp. 258-268 in the text book.


Download ppt "강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)"

Similar presentations


Ads by Google