Tải bản đầy đủ (.pdf) (12 trang)

16 1 19 master method tủ tài liệu training pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.42 MB, 12 trang )

Design and Analysis
of Algorithms I

Master Method
The Precise
Statement


THE MASTER METHOD
Cool Feature : a “black box” for solving
recurrences.
AssumpFon : all subproblems have
equal size.

Nextcore AI Gopal
Shangari


RECURRENCE FORMAT

1. Base Case : T(nti <= a constant for all sufficiently small n
2. For all larger n :

where
a = number of recursive calls (>= 1ti
b = input size shrinkage factor ( >
1ti
d = exponent in running Fme of “combine step” (>=0ti
Nextcore AI Gopal
[a,b,d independent of n ]
Shangari




The Master Method


Nextcore AI Gopal Shangari


Master Method

Examples
Design and Analysis
of Algorithms I


The Master Method


EXAMPLE #1
Merge Sort
a=2
b=2
d=1

a

Nextcore AI Gopal
Shangari



1, 2, 0 [Case 1]


Example #3
a=4
b=2
d=1

Integer MulKplicaKon Algorithm # 1

Same as gradeNschool
algorithm


BeP er than
the gradeN
school
algorithm!!!


Example #5
Strassen’s Matrix MulKplicaKon Algorithm
a=7
b=2
d=2
=> beats the naïve iteraKve algorithm !


Example #6
FicKKous Recurrence

a=2
b=2
d=2



×