Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014.

Similar presentations


Presentation on theme: "1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014."— Presentation transcript:

1 1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014

2 2 Course Outline Introduction and basic concepts Asymptotic notation Greedy algorithms Graph theory Amortized analysis Recursion Divide-and-conquer algorithms Randomized algorithms Dynamic programming algorithms NP-completeness

3 3 Master Theorem

4 4

5 5 In-class Exercises

6 6 Problem

7 7 Divide-and-Conquer Algorithms

8 8 Binary to Decimal conversion

9 9 Binary to Decimal Analysis

10 10 Faster Algorithm Approach: divide and conquer Divide the array in two parts, do each part separately Divide using an appropriate power of 10 Choose power of 10 that uses at least half of the bits

11 11 Faster Algorithm

12 12 Faster Algorithm

13 13 Exponential

14 14 Divide and Conquer

15 15 Time Complexity

16 16 Stock trading problem

17 17 Maximum Subarray Let’s consider the daily changes (difference from previous day): 13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7 Now the problem becomes: finding the range with largest sum In the example: 18, 20, -7, 12; sum is 43 How does that help?

18 18 Divide and Conquer If we divide the array in two, a maximum subarray may be in: The first half The second half In between (crossing division) We can calculate the best option for each, then select the largest First and second half can be solved by recursion Crossing subarray can be found in linear time Find largest sum that ends at midpoint Find largest sum that starts just after midpoint

19 19 Algorithm

20 20 Algorithm

21 21 Time Complexity


Download ppt "1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014."

Similar presentations


Ads by Google