Download - Master Theorem Examples
![Page 1: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/1.jpg)
Master Theorem Examples
CSCI 5870 - Data Structures and Algorithms
Robert W. KramerDepartment of Computer Science and Information Systems
Youngstown State University
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 2: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/2.jpg)
Example 1
Equation: W (n) = W (n2 ) + c · lgn
First question: divide-and-conquer, chip-and-conquer, orchip-and-be-conquered?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 3: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/3.jpg)
Example 1
Equation: W (n) = W (n2 ) + c · lgn
A: Divide-and-conquerSecond question: What are b, c and f (n)?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 4: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/4.jpg)
Example 1
Equation: W (n) = W (n2 ) + c · lgn
A: b = 1, c = 2, f (n) = c · lgnNow, find lgb, lgc , E and nE
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 5: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/5.jpg)
Example 1
Equation: W (n) = W (n2 ) + c · lgn
lgb = 0, lgc = 1, E = lgblgc = 0, nE = 1
Next: which is larger, f (n) or nE ?Also, can you find nx that fits between them?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 6: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/6.jpg)
Example 1
Equation: W (n) = W (n2 ) + c · lgn
f (n) is larger; however, there is no x where 1 ∈ o(nx) andnx ∈ o(lgn). Thus, neither case 1 nor case 3 applies. However,since f (n) ∈Θ(lgn = nE lg1 n), case 2 of the extended MasterTheorem applies.So, W (n) ∈Θ(nE lg1+1 n) = Θ(lg2 n).
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 7: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/7.jpg)
Example 2
Equation: W (n) = W (n2 ) + c ·n
First question: divide-and-conquer, chip-and-conquer, orchip-and-be-conquered?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 8: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/8.jpg)
Example 2
Equation: W (n) = W (n2 ) + c ·n
A: Divide-and-conquerSecond question: What are b, c and f (n)?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 9: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/9.jpg)
Example 2
Equation: W (n) = W (n2 ) + c ·n
A: b = 1, c = 2, f (n) = c ·nNow, find lgb, lgc , E and nE
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 10: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/10.jpg)
Example 2
Equation: W (n) = W (n2 ) + c ·n
lgb = 0, lgc = 1, E = lgblgc = 0, nE = 1
Next: which is larger, f (n) or nE ?Also, can you find nx that fits between them?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 11: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/11.jpg)
Example 2
Equation: W (n) = W (n2 ) + c ·n
f (n) is larger.We can choose n0.5, with 1 ∈ o(n0.5) and n0.5 ∈ o(f (n)). Thus,case 3 of the Master Theorem applies, andW (n) ∈Θ(f (n)) = Θ(n).
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 12: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/12.jpg)
Example 3
Equation: W (n) = 2W (n2 ) + c ·n
First question: divide-and-conquer, chip-and-conquer, orchip-and-be-conquered?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 13: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/13.jpg)
Example 3
Equation: W (n) = 2W (n2 ) + c ·n
A: Divide-and-conquerSecond question: What are b, c and f (n)?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 14: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/14.jpg)
Example 3
Equation: W (n) = 2W (n2 ) + c ·n
A: b = 2, c = 2, f (n) = c ·nNow, find lgb, lgc , E and nE
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 15: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/15.jpg)
Example 3
Equation: W (n) = 2W (n2 ) + c ·n
lgb = 1, lgc = 1, E = lgblgc = 1, nE = n
Next: which is larger, f (n) or nE ?Also, can you find nx that fits between them?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 16: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/16.jpg)
Example 3
Equation: W (n) = 2W (n2 ) + c ·n
Neither is larger; f (n) ∈Θ(nE ).Thus, case 2 of the Master Theorem applies, andW (n) ∈Θ(f (n) · logn) = Θ(n · lgn).
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 17: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/17.jpg)
Example 4
Equation: W (n) = 2W (n2 ) + c ·n · lgn
First question: divide-and-conquer, chip-and-conquer, orchip-and-be-conquered?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 18: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/18.jpg)
Example 4
Equation: W (n) = 2W (n2 ) + c ·n · lgn
A: Divide-and-conquerSecond question: What are b, c and f (n)?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 19: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/19.jpg)
Example 4
Equation: W (n) = 2W (n2 ) + c ·n · lgn
A: b = 2, c = 2, f (n) = c ·n · lgnNow, find lgb, lgc , E and nE
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 20: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/20.jpg)
Example 4
Equation: W (n) = 2W (n2 ) + c ·n · lgn
lgb = 1, lgc = 1, E = lgblgc = 1, nE = n
Next: which is larger, f (n) or nE ?Also, can you find nx that fits between them?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 21: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/21.jpg)
Example 4
Equation: W (n) = 2W (n2 ) + c ·n · lgn
f (n) is larger; however, you cannot separate f (n) and nE with apower of n (see example 1).However, f (n) ∈Θ(nE log1 n), so case 2 of the extended MasterTheorem applies, and W (n) ∈Θ(f (n) · log2 n) = Θ(n · lg2 n).
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 22: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/22.jpg)
Example 5
Equation: W (n) = 2W (n2 ) + c ·n2
First question: divide-and-conquer, chip-and-conquer, orchip-and-be-conquered?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 23: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/23.jpg)
Example 5
Equation: W (n) = 2W (n2 ) + c ·n2
A: Divide-and-conquerSecond question: What are b, c and f (n)?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 24: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/24.jpg)
Example 5
Equation: W (n) = 2W (n2 ) + c ·n2
A: b = 2, c = 2, f (n) = c ·n2
Now, find lgb, lgc , E and nE
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 25: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/25.jpg)
Example 5
Equation: W (n) = 2W (n2 ) + c ·n2
lgb = 1, lgc = 1, E = lgblgc = 1, nE = n
Next: which is larger, f (n) or nE ?Also, can you find nx that fits between them?
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples
![Page 26: Master Theorem Examples](https://reader033.vdocument.in/reader033/viewer/2022051515/552627eb550346dd6e8b4bd6/html5/thumbnails/26.jpg)
Example 5
Equation: W (n) = 2W (n2 ) + c ·n2
f (n) is clearly larger, and n1.5 fits nicely between f (n) and nE .Thus, case 3 of the Master Theorem applies, andW (n) ∈Θ(f (n)) = Θ(n2).
CSCI 5870 - Data Structures and Algorithms Master Theorem Examples