Algorithms and Dynamic Programming in Winter 2020 Lecture

cse 417 algorithms n.w
1 / 17
Embed
Share

Explore the concepts of Divide and Conquer, Dynamic Programming, and fast integer multiplication algorithms like Karatsuba. Dive into topics like mergesort, quicksort, and more. Learn about advanced techniques such as Recursive Multiplication Algorithm and Karatsuba's Algorithm for multiplying n-digit integers. Discover the power of Dynamic Programming and Weighted Interval Scheduling in this comprehensive lecture series.

  • Algorithms
  • Dynamic Programming
  • Winter 2020
  • Divide and Conquer
  • Karatsuba

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSE 417 Algorithms Lecture 17, Winter 2020 Divide and Conquer Dynamic Programming

  2. Announcements

  3. Divide and Conquer Algorithms Mergesort, Quicksort Strassen s Algorithm Median Inversion counting Closest Pair Algorithm (2d) Integer Multiplication (Karatsuba s Algorithm)

  4. Integer Arithmetic 9715480283945084383094856701043643845790217965702956767 + 1242431098234099057329075097179898430928779579277597977 Runtime for standard algorithm to add two n digit numbers: 2095067093034680994318596846868779409766717133476767930 X 5920175091777634709677679342929097012308956679993010921 Runtime for standard algorithm to multiply two n digit numbers:

  5. Recursive Multiplication Algorithm (First attempt) x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = (x1 2n/2 + x0) (y1 2n/2 + y0) = x1y1 2n + (x1y0 + x0y1)2n/2 + x0y0 Recurrence: Run time:

  6. Simple algebra x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = x1y1 2n + (x1y0 + x0y1) 2n/2 + x0y0 p = (x1 + x0)(y1 + y0) = x1y1 + x1y0 + x0y1 + x0y0

  7. Karatsubas Algorithm Multiply n-digit integers x and y Let x = x1 2n/2 + x0 and y = y1 2n/2 + y0 Recursively compute a = x1y1 b = x0y0 p = (x1 + x0)(y1 + y0) Return a2n + (p a b)2n/2 + b Recurrence: T(n) = 3T(n/2) + cn log23 = 1.58496250073

  8. Fast Integer Multiplication Grade School O(n2) Karatsuba O(n1.58) Toom-Cook O(n1.46) [For 3 pieces] O(n1+eps) [For k pieces] Schonhage-Strassen Fast Fourier Transform based algorithm O(n log n loglog n) Becomes practical for ~25,000 digits

  9. Dynamic Programming

  10. Intervals sorted by end time Dynamic Programming Weighted Interval Scheduling Given a collection of intervals I1, ,In with weights w1, ,wn, choose a maximum weight set of non-overlapping intervals 4 6 3 5 7 6

  11. Intervals sorted by end time Optimality Condition Opt[ j ] is the maximum weight independent set of intervals I1, I2, . . ., Ij Opt[ j ] = max( Opt[ j 1], wj + Opt[ p[ j ] ]) Where p[ j ] is the index of the last interval which finishes before Ij starts

  12. Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), wj + MaxValue(p[ j ])) Worst case run time: 2n

  13. A better algorithm M[ j ] initialized to -1 before the first recursive call for all j MaxValue(j) = if j = 0 return 0; else if M[ j ] != -1 return M[ j ]; else M[ j ] = max(MaxValue(j-1), wj + MaxValue(p[ j ])); return M[ j ];

  14. Iterative Algorithm Express the MaxValue algorithm as an iterative algorithm MaxValue { }

  15. Fill in the array with the Opt values Opt[ j ] = max (Opt[ j 1], wj + Opt[ p[ j ] ]) 2 4 7 4 6 7 6

  16. Computing the solution Opt[ j ] = max (Opt[ j 1], wj + Opt[ p[ j ] ]) Record which case is used in Opt computation 2 4 7 4 6 7 6

  17. Dynamic Programming The most important algorithmic technique covered in CSE 421 Key ideas Express solution in terms of a polynomial number of sub problems Order sub problems to avoid recomputation

Related


More Related Content