Divide and conquer

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Format of Divide and Conquer

in picture

Selection Algorithm 2

in picture

Selection Algorithm 3

in picture

Master Recurrence Theorem problem 3 (case 3)

- Equation: 9T(n/3) + theta(n) -> a = 9 -> b = 3 -> k = 1 - Solution: -> b^k = 3 -> a > b^k (9 > 3) -> T(n) = theta(n^(logb a)) => theta(n^(log3 9)) => theta(n^2)

Master Recurrence Theorem problem 1 (merge sort)

- Equation: T(n) = 2 T(n/2) + theta(n) -> a = 2 -> b = 2 -> k = 1 - Solution: -> b^k = 2 -> a = b^k (2 = 2) -> T(n) = theta(n^k lg n) => theta(n^1 lg n) => theta(n lg n)

Master Recurrence Theorem problem 4 (case 2)

- Equation: T(n) = 3T(n/2) + theta(n^2) -> a = 3 -> b = 2 -> k = 2 - Solution: -> b^k = 4 -> a < b^k (3 < 4) -> T(n) = theta(n^k) => theta(n^2)

Polynomial multiplication problem

- Equation: T(n) = 4T(n/2) + theta(n) -> a = 4 -> b = 2 -> k = 1 - Solution: -> b^k = 2 -> a > b^k (4 > 2) -> T(n) = theta(n^(logb a)) => theta(n^(log2 4)) => theta(n^2)

Master Recurrence Theorem problem 2 (binary search)

- Equation: T(n) = T(n/2) + theta(1) -> a = 1 -> b = 2 -> k = 0 - Solution: -> b^k = 1 -> a = b^k (1 = 1) -> T(n) = theta(n^k lg n) => theta(n^0 lg n) => theta(lg n)

Majority element algorithm

- If you find an candidate (m), does that mean there exist an majority? -> false, you can have an candidate and have no majority - Equation: T(n) = T(n/2) + theta(n) -> a = 1 -> b = 2 -> k = 1 - Solution: -> b^k = 2 -> a < b^k (1 < 2) -> T(n) = theta(n^k) => theta(n)

Karatsuba's Algorithm (polynomial multiplication)

- Proof in picture - Equation: T(n) = 3T(n/2) + theta(n) -> a = 3 (Note we were able to lower the recursive call due to Karatsuba's Algorithm) -> b = 2 -> k = 1 - Solution : -> b^k = 2 -> a > b^k (3 > 2) -> T(n) = theta(n^(logb a)) => theta(n^log2 3) => theta(n^1.58) - Note: the algorithm reduce the run time from n^2 to n^1.58

Selection Algorithm 1

- Steps: ->Sort the array (A[]) into ascending order -> then return A[k] - Run time: theta(n lg n), if using merge/quick sorting algorithm

Master Recurrence Theorem

- formulas in picture -> a is the number of recursive calls -> T(n/b) is the problem size of recursive calls -> theta(n^k) is the number of work (run time)

Analysis of Algorithm 3 for selection problem (part 2):

- in picture - Algorithm 3 worst case run time is theta(n)

Strassen's algorithm (algorithm 2 for Matrix Multiplication)

Equation: T(n) = 7T(n/2) + theta(n^2) -> a = 7 -> b = 2 -> k = 2 - Solution: -> b^k = 4 -> a > b^k (7 > 4) -> T(n) = theta(n^(logb a)) => theta(n^(log2 7)) => theta(n^2.81)

Matrix Multiplication (Algorithm 1)

Equation: T(n) = 8T(n/2) + theta(n^2) -> a = 8 -> b = 2 -> k = 2 - Solution: -> b^k = 4 -> a > b^k (8 > 4) -> T(n) = theta(n^(logb a)) => theta(n^(log2 8)) => theta(n^3)

selection problem

given an array A[1...n] and value k where 1 <= k <=n, find and return the kth smallest element in A

Analysis of Algorithm 3 for selection problem (part1):

in picture


संबंधित स्टडी सेट्स

Thoracic Cavity and Temporomandibular Joint KIAS

View Set

Chapter 46 Pathophysiology NCLEX-Style Review Questions

View Set