Discrete Mathematics Recurrence and Its Applications 2016 Recurrence

  • Slides: 24
Download presentation
이산수학(Discrete Mathematics) 점화와 응용 (Recurrence and Its Applications) 2016년 봄학기 강원대학교 컴퓨터과학전공 문양세

이산수학(Discrete Mathematics) 점화와 응용 (Recurrence and Its Applications) 2016년 봄학기 강원대학교 컴퓨터과학전공 문양세

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page 2 Discrete Mathematics by Yang-Sae Moon

Recurrence Relations A recurrence relation (R. R. , or just recurrence) for a sequence

Recurrence Relations A recurrence relation (R. R. , or just recurrence) for a sequence {an} is an equation that expresses an in terms of one or more previous elements a 0, …, an− 1 of the sequence, for all n≥n 0. (수열 {an}에 대한 점화 관계란 an을 이전의 항들인 a 0, …, an− 1들을 사용하여 표시 하는 등식이다. 대표적인 예가 피보나치 수열) A particular sequence is said to solve the given recurrence relation if it is consistent with the definition of the recurrence. (특정한 수열이 주어진 점화 관계를 만족하면 해당 수열을 주어진 점화 관계의 해라 한다. 다음 페이지의 예를 참조) • A given recurrence relation may have many solutions. (주어진 점화 관계는 하나 이상의 많은 해를 가질 수 있다. ) Page 3 Discrete Mathematics by Yang-Sae Moon

Recurrence Relation Example Recurrence Relations Consider the recurrence relation an = 2 an− 1

Recurrence Relation Example Recurrence Relations Consider the recurrence relation an = 2 an− 1 − an− 2 (n≥ 2). Which of the following are solutions? an = 3 n Yes an = 2 n No an = 5 Yes Page 4 Discrete Mathematics by Yang-Sae Moon

이자율 계산 예제 (1/3) Recurrence Relations Recurrence relation for growth of a bank account

이자율 계산 예제 (1/3) Recurrence Relations Recurrence relation for growth of a bank account with P% interest per given period: (이자율이 P%일 때, 총액 계산) Mn = Mn− 1 + (P/100)Mn− 1 • Mn: 이번 달의 총액 • Mn− 1: 지난 달의 총액 • (P/100)Mn− 1: 지난 달의 이자 Page 5 Discrete Mathematics by Yang-Sae Moon

이자율 계산 예제 (2/3) Mn Recurrence Relations = Mn− 1 + (P/100)Mn− 1 =

이자율 계산 예제 (2/3) Mn Recurrence Relations = Mn− 1 + (P/100)Mn− 1 = (1 + P/100) Mn− 1 = r Mn− 1 (let r = 1 + P/100) = r (r Mn− 2) = r·r·(r Mn− 3) …and so on to… = r n M 0 Page 6 Discrete Mathematics by Yang-Sae Moon

이자율 계산 예제 (3/3) Recurrence Relations 예제: 원금이 10, 000 달러이고, 1년 이자가 11%일

이자율 계산 예제 (3/3) Recurrence Relations 예제: 원금이 10, 000 달러이고, 1년 이자가 11%일 때, 복리로 계산하면 30년 후 계좌 잔고는? • Mn = Mn− 1 + (11/100)Mn− 1 = (1. 11)Mn− 1 • M 1 = (1. 11)M 0 • M 2 = (1. 11)M 1 = (1. 11)2 M 0 • M 3 = (1. 11)M 2 = (1. 11)3 M 0 • … • Mn = (1. 11)Mn-1 = (1. 11)n. M 0 • M 30 = (1. 11)30 M 0 = (1. 11)30 x 10, 000 = $228, 922. 97 Page 7 // M 0 = 10, 000 Discrete Mathematics by Yang-Sae Moon

하노이 탑 예제 (1/3) Recurrence Relations Problem: Get all disks from peg 1 to

하노이 탑 예제 (1/3) Recurrence Relations Problem: Get all disks from peg 1 to peg 2. (말뚝 1에 있는 모든 디스크를 말뚝 2로 옮긴다. ) • Only move 1 disk at a time. (한 번에 한 개의 디스크만 옮길 수 있다. ) • Never set a larger disk on a smaller one. (작은 디스크 위에 큰 디스크를 올려 놓을 수는 없다. ) Peg #1 Peg #2 Page 9 Peg #3 Discrete Mathematics by Yang-Sae Moon

하노이 탑 예제 (2/3) Recurrence Relations Let Hn = # of moves for a

하노이 탑 예제 (2/3) Recurrence Relations Let Hn = # of moves for a stack of n disks. (Hn을 n개의 디스크 스택을 옮기는 데 필요한 디스크의 이동 횟수라 하자. ) Optimal strategy: • Move top n− 1 disks to spare peg. (Hn− 1 moves) • Move bottom disk. (1 move) • Move top n− 1 to bottom disk. (Hn− 1 moves) Note: Hn = 2 Hn− 1 + 1 Page 10 Discrete Mathematics by Yang-Sae Moon

하노이 탑 예제 (3/3) Recurrence Relations Hn = 2 Hn− 1 + 1 =

하노이 탑 예제 (3/3) Recurrence Relations Hn = 2 Hn− 1 + 1 = 2 (2 Hn− 2 + 1) + 1 = 22 Hn− 2 + 1 = 22(2 Hn− 3 + 1) + 2 + 1 = 23 Hn− 3 + 22 + 1 … = 2 n− 1 H 1 + 2 n− 2 + … + 2 + 1 = 2 n− 1 + 2 n− 2 + … + 2 + 1 (since H 1 = 1) = = 2 n − 1 Page 11 Discrete Mathematics by Yang-Sae Moon

More Examples (1/2) Recurrence Relations 예제 (비트 스트링 문제): 두 개의 연속적인 0들을 갖지

More Examples (1/2) Recurrence Relations 예제 (비트 스트링 문제): 두 개의 연속적인 0들을 갖지 않는(0이 연달아 2개 나오지 않는) 길이 n 의 비트 스트링 개수에 대한 점화 관계와 초기 조건을 제시하라. # of bit strings of length n with no two consecutive 0 s: End with a 1: Any bit string of length n – 1 with no two consecutive 0 s 1 an-1 End with a 0: Any bit string of length n – 2 with no two consecutive 0 s 1 0 an-2 Total: an = an-1 + an-2 • 점화 관계: an = an-1 + an-2 • 초기 조건: a 1 = 2 = |{0, 1}|, a 2 = 3 = |{01, 10, 11}| Page 12 Discrete Mathematics by Yang-Sae Moon

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page 14 Discrete Mathematics by Yang-Sae Moon

Divide & Conquer Recurrence Relations Divide and Conquer Main points so far: Many types

Divide & Conquer Recurrence Relations Divide and Conquer Main points so far: Many types of problems are solvable by reducing a problem of size n into some number a of independent subproblems, each of size n/b , where a 1 and b>1. (많은 경우에 있어서, 크기 n의 문제를 a개의 크기 n/b 의 작은 문제로 바꾸어 처리할 수 있다. ) The time complexity to solve such problems is given by a recurrence relation: T(n) = a·T( n/b ) + g(n) (이런 경우의 시간 복잡도는 T(n)의 점화 관계로 나타낼 수 있다. ) Time to break problem up into sub-problems Time for each sub-problem Page 15 Discrete Mathematics by Yang-Sae Moon

Divide & Conquer Examples Divide and Conquer Binary search: Break list into 1 sub-problem

Divide & Conquer Examples Divide and Conquer Binary search: Break list into 1 sub-problem (smaller list) (so a=1) of size n/2 (so b=2). • So T(n) = T( n/2 )+c (g(n)=c constant) Merge sort: Break list of length n into 2 sub-lists (a=2), each of size n/2 (so b=2), then merge them, in g(n) = (n) time. • So T(n) = 2 T( n/2 ) + cn (roughly, for some c) Page 16 Discrete Mathematics by Yang-Sae Moon

Fast Multiplication Example (1/3) Divide and Conquer The ordinary grade-school algorithm takes (n 2)

Fast Multiplication Example (1/3) Divide and Conquer The ordinary grade-school algorithm takes (n 2) steps to multiply two n-digit numbers. (학교에서 배운 방법에 따르면, n자리인 두 수의 곱은 (n 2) 스텝이 필요하다. ) • This seems like too much work! So, let’s find a faster multiplication algorithm! To find the product cd of two 2 n-digit base-b numbers, c=(c 2 n-1 c 2 n-2…c 0)b and d=(d 2 n-1 d 2 n-2…d 0)b, first, we break c and d in half: c=bn. C 1+C 0, d=bn. D 1+D 0, (e. g. , 4321 = 102 43+21) and then. . . (see next slide) Page 17 Discrete Mathematics by Yang-Sae Moon

Fast Multiplication Example (2/3) Divide and Conquer Zero (Factor last polynomial) Three multiplications, each

Fast Multiplication Example (2/3) Divide and Conquer Zero (Factor last polynomial) Three multiplications, each with n-digit numbers Page 18 Discrete Mathematics by Yang-Sae Moon

Fast Multiplication Example (3/3) Divide and Conquer Notice that the time complexity T(n) of

Fast Multiplication Example (3/3) Divide and Conquer Notice that the time complexity T(n) of the fast multiplication algorithm obeys the recurrence: T(2 n)=3 T(n)+ (n) Time to do the needed adds & subtracts of n-digit and 2 n-digit numbers i. e. , T(n)=3 T(n/2)+ (n) So a=3, b=2. ( The order will be reduced …) Page 19 Discrete Mathematics by Yang-Sae Moon

The Master Theorem Divide and Conquer Consider a function f(n) that, for all n=bk

The Master Theorem Divide and Conquer Consider a function f(n) that, for all n=bk for all k Z+, satisfies the recurrence relation: (n=bk 일 때, 다음 점화 관계가 성립하면) f(n) = af(n/b) + cnd with a≥ 1, integer b>1, real c>0, d≥ 0. Then: Proof of theorem is …. omitted. Page 20 Discrete Mathematics by Yang-Sae Moon

Master Theorem Examples (1/3) Divide and Conquer Recall that complexity of fast multiplication was:

Master Theorem Examples (1/3) Divide and Conquer Recall that complexity of fast multiplication was: T(n)=3 T(n/2)+ (n) Thus, a=3, b=2, d=1. So a > bd, so case 3 of the master theorem applies, so: which is O(n 1. 58…), so the new algorithm is strictly faster than ordinary (n 2) multiply! Page 21 Discrete Mathematics by Yang-Sae Moon

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page

강의 내용 Recurrence and Its Applications 점화 관계(Recurrence Relations) 분할과 정복(Divide and Conquer) Page 24 Discrete Mathematics by Yang-Sae Moon