Presentation is loading. Please wait.

Presentation is loading. Please wait.

이산수학(Discrete Mathematics)

Similar presentations


Presentation on theme: "이산수학(Discrete Mathematics)"— Presentation transcript:

1 이산수학(Discrete Mathematics)
분할과 정복 (Divide and Conquer) 2014년 봄학기 강원대학교 컴퓨터과학전공 문양세

2 Time for each sub-problem
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 sub-problems, 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 for each sub-problem Time to break problem up into sub-problems

3 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) = 2T(n/2) + cn (roughly, for some c)

4 Fast Multiplication Example (1/3)
Divide and Conquer The ordinary grade-school algorithm takes (n2) steps to multiply two n-digit numbers. (학교에서 배운 방법에 따르면, n자리인 두 수의 곱은 (n2) 스텝이 필요하다.) This seems like too much work! So, let’s find a faster multiplication algorithm! To find the product cd of two 2n-digit base-b numbers, c=(c2n-1c2n-2…c0)b and d=(d2n-1d2n-2…d0)b, first, we break c and d in half: c=bnC1+C0, d=bnD1+D0, (e.g., 4321 = 10243+21) and then... (see next slide)

5 Fast Multiplication Example (2/3)
Divide and Conquer Zero Three multiplications, each with n-digit numbers (Factor last polynomial)

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

7 with a≥1, integer b>1, real c>0, d≥0. Then:
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 the theorem is …. omitted.

8 Master Theorem Examples (1/3)
Divide and Conquer Recall that complexity of fast multiplication was: T(n)=3T(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(n1.58…), so the new algorithm is strictly faster than ordinary (n2) multiply!

9 Master Theorem Examples (2/3)
Divide and Conquer 예제(Binary Search): 이진 탐색의 복잡도는 얼마인가(비교 수를 추정하라)? 이진 탐색의 점화 관계: T(n) = T(n/2)+c (n 이 짝수라 가정) 매스터 정리로 보면, a = 1, b = 2, d = 0으로서, a = 1 = bd인 두 번째 경우에 해당한다. 결국, 다음과 같은 과정에 의해 O(logn)이 된다.

10 Master Theorem Examples (3/3)
Divide and Conquer 예제(Merge Sort): 합병 정렬의 복잡도는 얼마인가(비교 수를 추정하라)? 이진 탐색의 점화 관계: T(n) = 2T(n/2)+cn (n 이 짝수라 가정) 매스터 정리로 보면, a = 2, b = 2, d = 1로서, a = 2 = bd인 두 번째 경우에 해당한다. 결국, 다음과 같은 과정에 의해 O(nlogn)이 된다.


Download ppt "이산수학(Discrete Mathematics)"

Similar presentations


Ads by Google