CSE 421. Dynamic Programming Shortest Paths with Negative Weights Yin Tat Lee

Size: px
Start display at page:

Download "CSE 421. Dynamic Programming Shortest Paths with Negative Weights Yin Tat Lee"

Transcription

1 CSE 421 Dynamic Programming Shortest Paths with Negative Weights Yin Tat Lee 1

2 Shortest Paths with Neg Edge Weights Given a weighted directed graph G = V, E and a source vertex s, where the weight of edge (u,v) is c u,v (that can be negative) Goal: Find the shortest path from s to all vertices of G. Recall that Dikjstra s Algorithm fails when weights are negative source s 2 3 s

3 Impossibility on Graphs with Neg Cycles Observation: No solution exists if G has a negative cycle. This is because we can minimize the length by going over the cycle again and again. So, suppose G does not have a negative cycle s

4 DP for Shortest Path (First Attempt) Def: Let OPT(v) be the length of the shortest s - v path OPT v = 0 if v = s min OPT u + c u,v u: u,v an edge The formula is correct. But it is not clear how to compute it. 4

5 DP for Shortest Path Def: Let OPT(v, i) be the length of the shortest s - v path with at most i edges. Let us characterize OPT(v, i). Case 1: OPT(v, i) path has less than i edges. Then, OPT v, i = OPT v, i 1. Case 2: OPT(v, i) path has exactly i edges. Let s, v 1, v 2,, v i 1, v be the OPT(v, i) path with i edges. Then, s, v 1,, v i 1 must be the shortest s - v i 1 path with at most i 1 edges. So, OPT v, i = OPT v i 1, i 1 + c vi 1,v 5

6 DP for Shortest Path Def: Let OPT(v, i) be the length of the shortest s - v path with at most i edges. 0 if v = s OPT v, i = if v s, i = 0 min(opt v, i 1, min OPT u, i 1 + c u,v) u: u,v an edge So, for every v, OPT v,? is the shortest path from s to v. But how long do we have to run? Since G has no negative cycle, it has at most n 1 edges. So, OPT(v, n 1) is the answer. 6

7 Bellman Ford Algorithm for v=1 to n if v s then M[v,0]= M[s,0]=0. for i=1 to n-1 for v=1 to n M[v,i]=M[v,i-1] for every edge (u,v) M[v,i]=min(M[v,i], M[u,i-1]+c u,v ) Running Time: O nm Can we test if G has negative cycles? Yes, run for i=1 3n and see if the M[v,n-1] is different from M[v,3n] 7

8 DP Techniques Summary Recipe: Follow the natural induction proof. Find out additional assumptions/variables/subproblems that you need to do the induction Strengthen the hypothesis and define w.r.t. new subproblems Dynamic programming techniques. Ordering is important: longest path in DAG Adding a new variable: knapsack. Dynamic programming over intervals: RNA secondary structure. Top-down vs. bottom-up: Different people have different intuitions Bottom-up is useful to optimize the memory 8

9 CSE 421 Divide and Conquer Ο(n logn) time polynomial multiplication 9

10 Multiplication Polynomials Naïve: (n 2 ) Karatsuba: (n 1.59 ) Best known: (n log n) "Fast Fourier Transform FFT widely used for signal processing Integers Similar, but some ugly details re: carries, etc. due to Schonhage- Strassen in 1971 gives (n log n loglog n) Improvement in 2007 due to Furer gives (n log n 2 log* n ) Used in practice in symbolic manipulation systems like Maple 10

11 Interpolation Given set of values at 5 points 11

12 Interpolation Given set of values at 5 points Can find unique degree 4 polynomial going through these points 12

13 Multiplying Polynomials by Evaluation & Interpolation Any degree n-1 polynomial R(y) is determined by R(y 0 ),... R(y n-1 ) for any n distinct y 0,...,y n-1 To compute PQ (assume degree at most n/2-1) Evaluate P(y 0 ),..., P(y n-1 ) Evaluate Q(y 0 ),...,Q(y n-1 ) Multiply values P(y i )Q(y i ) for i=0,...,n-1 Interpolate to recover PQ 13

14 Interpolation Given values of degree n-1 polynomial R at n distinct points y 0,,y n-1 R(y 0 ),,R(y n-1 ) Compute coefficients c 0,,c n-1 such that R(x)=c 0 +c 1 x+c 2 x 2 + +c n-1 x n-1 System of linear equations in c 0,,c n-1 c 0 +c 1 y 0 +c 2 y c n-1 y n-1 0 =R(y 0 ) known c 0 +c 1 y 1 +c 2 y c n-1 y n-1 1 =R(y 1 ) c 0 +c 1 y n-1 +c 2 y n c n-1 y n-1 n-1 =R(y n-1 ) unknown 14

15 Interpolation: n equations in n unknowns Matrix form of the linear system 1 y 0 y 02 y n-1 0 c 0 R(y 0 ) 1 y 1 y 12 y n-1 1 c 1 R(y 1 ) c 2 =... 1 y n-1 y n-12 y n-1 n-1 c n-1 R(y n-1 ) Fact: Determinant of the matrix is P i j (y i -y j ) which is not 0 since points are distinct System has a unique solution c 0,,c n-1 15

16 Evaluation & Interpolation P: a 0,a 1,...,a n/2-1 Q: b 0,b 1,...,b n/2-1 evaluation at y 0,...,y n-1 O(?) ordinary polynomial multiplication (n 2 ) c k i j k a b i j R:c 0,c 1,...,c n-1 interpolation from y 0,...,y n-1 O(?) P(y 0 ),Q(y 0 ) P(y 1 ),Q(y 1 )... P(y n-1 ),Q(y n-1 ) point-wise multiplication of numbers O(n) R(y 0 ) P(y 0 ) Q(y 0 ) R(y 1 ) P(y 1 ) Q(y 1 )... R(y n-1 ) P(y n-1 ) Q(y n-1 ) 16

17 Karatsuba s algorithm and evaluation and interpolation Strassen gave a way of doing 2x2 matrix multiplies with fewer multiplications Karatsuba s algorithm can be thought of as a way of multiplying degree 1 polynomials (which have 2 coefficients) using fewer multiplications PQ=(P 0 +P 1 z)(q 0 +Q 1 z) = P 0 Q 0 + (P 1 Q 0 +P 0 Q 1 )z + P 1 Q 1 z 2 Evaluate at 0,1,-1 (Could also use other points) A = P(0)Q(0)= P 0 Q 0 C = P(1)Q(1)=(P 0 +P 1 )(Q 0 +Q 1 ) D = P(-1)Q(-1)=(P 0 -P 1 )(Q 0 -Q 1 ) Interpolating, Karatsuba s Mid=(C-D)/2 and B=(C+D)/2-A 17

18 Evaluation at Special Points Evaluation of polynomial at 1 point takes O(n) time So 2n points (naively) takes O(n 2 ) no savings But the algorithm works no matter what the points are So choose points that are related to each other so that evaluation problems can share subproblems 18

19 The key idea: Evaluate at related points P(x) = a 0 +a 1 x+a 2 x 2 +a 3 x 3 +a 4 x a n-1 x n-1 = a 0 +a 2 x 2 +a 4 x a n-2 x n-2 + a 1 x+a 3 x 3 +a 5 x a n-1 x n-1 = P even (x 2 ) + x P odd (x 2 ) P(-x)=a 0 -a 1 x+a 2 x 2 -a 3 x 3 +a 4 x a n-1 x n-1 = a 0 +a 2 x 2 +a 4 x a n-2 x n-2 - (a 1 x+a 3 x 3 +a 5 x a n-1 x n-1 ) = P even (x 2 ) - x P odd (x 2 ) where P even (z) = a 0 +a 2 z +a 4 z a n-2 z n/2-1 and P odd (z) = a 1 +a 3 z +a 5 z a n-1 z n/2-1 19

20 The key idea: Evaluate at related points So if we have half the points as negatives of the other half i.e., y n/2 = -y 0, y n/2+1 = -y 1,,y n-1 = -y n/2-1 then we can reduce the size n problem of evaluating degree n-1 polynomial P at n points to evaluating 2 degree n/2-1 polynomials P even and P odd at n/2 points y 02, y n/2-12 and recombine answers with O(1) extra work per point But to use this idea recursively we need half of y 02, y n/2-1 2 to be negatives of the other half If y n/4 2 = -y 02, say, then (y n/4 /y 0 ) 2 = -1 Motivates use of complex numbers as evaluation points 20

21 Complex Numbers i 2 = -1 e+fi -1 c+di q j i j q a+bi 1 To multiply complex numbers: 1. add angles 2. multiply lengths (all length 1 here) e+fi = (a+bi)(c+di) e 2pi = 1 e pi = -1 -i a+bi =cos q +i sin q = e iq c+di =cos j +i sin j = e ij e+fi =cos (q j) +i sin (q j) = e i(q j) 21

22 Primitive n th root of 1 2p/n w=w n = e i w 3 w 2 =i w Let w = w n = ei 2p /n = cos (2p/n) +i sin (2p/n) w 4 =-1 w 0 =1=w 8 w 5 w 6 = -i w 7 i 2 = -1 e 2p i = 1 22

23 Facts about w=e 2pi /n for even n w = e 2pi /n for i = 1 w n = 1 w n/2 = -1 w n/2+k = - w k for all values of k w 2 = e 2pi / m where m=n/2 w k = cos(2kp/n)+i sin(2kp/n) so can compute with powers of w w k is a root of x n -1= (x-1)(x n-1 +x n ) =0 for k 0, w k 1 so w k(n-1) +w k(n-2) + +1=0 but 23

24 The key idea for n even P(w) = a 0 +a 1 w+a 2 w 2 +a 3 w 3 +a 4 w a n-1 w n-1 = a 0 +a 2 w 2 +a 4 w a n-2 w n-2 + a 1 w+a 3 w 3 +a 5 w a n-1 w n-1 = P even (w 2 ) + w P odd (w 2 ) P(-w)=a 0 -a 1 w+a 2 w 2 -a 3 w 3 +a 4 w a n-1 w n-1 = a 0 +a 2 w 2 +a 4 w a n-2 w n-2 - (a 1 w+a 3 w 3 +a 5 w a n-1 w n-1 ) = P even (w 2 ) - w P odd (w 2 ) where P even (x) = a 0 +a 2 x +a 4 x a n-2 x n/2-1 and P odd (x) = a 1 +a 3 x +a 5 x a n-1 x n/2-1 24

25 The recursive idea for n a power of 2 Goal: Evaluate P at 1,w,w 2,w 3,...,w n-1 Now P even and P odd have degree n/2-1 where P(w k )=P even (w 2k )+w k P odd (w 2k ) P(-w k )=P even (w 2k )-w k P odd (w 2k ) Recursive Algorithm Evaluate P even at 1,w 2,w 4,...,w n-2 Evaluate P odd at 1,w 2,w 4,...,w n-2 Combine to compute P at 1,w,w 2,...,w n/2-1 Combine to compute P at -1,-w,-w 2,...,-w n/2-1 (i.e. at w n/2, w n/2+1, w n/2+2,..., w n-1 ) w 2 is e2pi /m where m=n/2 so problems are of same type but smaller size 25

26 Analysis and more Run-time T(n)=2 T(n/2)+cn so T(n)=O(n log n) So much for evaluation... what about interpolation? Given r 0 =R(1), r 1 =R(w), r 2 =R(w 2 ),..., r n-1 =R(w n-1 ) Compute c 0, c 1,...,c n-1 s.t. R(x)=c 0 +c 1 x+...+c n-1 x n-1 26

27 Interpolation Evaluation: strange but true Non-obvious fact: If we define a new polynomial S(x) = r 0 + r 1 x + r 2 x r n-1 x n-1 where r 0, r 1,..., r n-1 are the evaluations of R at 1, w,..., w n-1 Then c k =S(w -k )/n for k=0,...,n-1 Relies on the fact the interpolation (inverse) matrix has ij entry w -(i+j) /n instead of w i+j So... evaluate S at 1,w -1,w -2,...,w -(n-1) then divide each answer by n to get the c 0,...,c n-1 w -1 behaves just like w did so the same O(n log n) evaluation algorithm applies! 27

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide n c: Solve the problem

More information

CSE 421 Algorithms: Divide and Conquer

CSE 421 Algorithms: Divide and Conquer CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Richard Anderson, Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge

More information

CSE 421 Dynamic Programming

CSE 421 Dynamic Programming CSE Dynamic Programming Yin Tat Lee Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs compatible if they don t overlap. Goal: find maximum

More information

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication )

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) CSE 548: Analysis of Algorithms Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015 Coefficient Representation

More information

Multiplying huge integers using Fourier transforms

Multiplying huge integers using Fourier transforms Fourier transforms October 25, 2007 820348901038490238478324 1739423249728934932894??? integers occurs in many fields of Computational Science: Cryptography Number theory... Traditional approaches to

More information

CSE 202 Dynamic Programming II

CSE 202 Dynamic Programming II CSE 202 Dynamic Programming II Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally,

More information

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Divide and Conquer: Polynomial Multiplication Version of October 7, 2014 Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Outline Outline: Introduction The polynomial multiplication

More information

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 2331 Algorithms Steve Lai

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 2331 Algorithms Steve Lai Dynamic Programming Reading: CLRS Chapter 5 & Section 25.2 CSE 233 Algorithms Steve Lai Optimization Problems Problems that can be solved by dynamic programming are typically optimization problems. Optimization

More information

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 58: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 28 Announcement: Homework 3 due February 5 th at :59PM Midterm Exam: Wed, Feb 2 (8PM-PM) @ MTHW 2 Recap: Dynamic Programming

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Dynamic Programming Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Paradigms for Designing Algorithms Greedy algorithm Make a

More information

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing

More information

Integer Multiplication

Integer Multiplication Integer Multiplication in almost linear time Martin Fürer CSE 588 Department of Computer Science and Engineering Pennsylvania State University 1/24/08 Karatsuba algebraic Split each of the two factors

More information

CS S Lecture 5 January 29, 2019

CS S Lecture 5 January 29, 2019 CS 6363.005.19S Lecture 5 January 29, 2019 Main topics are #divide-and-conquer with #fast_fourier_transforms. Prelude Homework 1 is due Tuesday, February 5th. I hope you ve at least looked at it by now!

More information

Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion

Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion During the past week, we learnt about inductive reasoning, in which we broke down a problem of size n, into one

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 //8 Fast Integer Division Too (!) Schönhage Strassen algorithm CS 8: Algorithm Design and Analysis Integer division. Given two n-bit (or less) integers s and t, compute quotient q = s / t and remainder

More information

Integer multiplication with generalized Fermat primes

Integer multiplication with generalized Fermat primes Integer multiplication with generalized Fermat primes CARAMEL Team, LORIA, University of Lorraine Supervised by: Emmanuel Thomé and Jérémie Detrey Journées nationales du Calcul Formel 2015 (Cluny) November

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 208 Announcement: Homework 3 due February 5 th at :59PM Final Exam (Tentative): Thursday, May 3 @ 8AM (PHYS 203) Recap: Divide

More information

Fast Polynomial Multiplication

Fast Polynomial Multiplication Fast Polynomial Multiplication Marc Moreno Maza CS 9652, October 4, 2017 Plan Primitive roots of unity The discrete Fourier transform Convolution of polynomials The fast Fourier transform Fast convolution

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 4: Divide and Conquer (I) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Divide and Conquer ( DQ ) First paradigm or framework DQ(S)

More information

Dynamic Programming 1

Dynamic Programming 1 Dynamic Programming 1 lgorithmic Paradigms Divide-and-conquer. Break up a problem into two sub-problems, solve each sub-problem independently, and combine solution to sub-problems to form solution to original

More information

CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure

CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure CSE Weighted Interval Scheduling, Knapsack, RNA Secondary Structure Shayan Oveis haran Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs

More information

Chapter 6. Dynamic Programming. CS 350: Winter 2018

Chapter 6. Dynamic Programming. CS 350: Winter 2018 Chapter 6 Dynamic Programming CS 350: Winter 2018 1 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into

More information

Introduction to Algorithms 6.046J/18.401J/SMA5503

Introduction to Algorithms 6.046J/18.401J/SMA5503 Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 3 Prof. Piotr Indyk The divide-and-conquer design paradigm. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving

More information

Fast Convolution; Strassen s Method

Fast Convolution; Strassen s Method Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master

More information

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 6331: Algorithms Steve Lai

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 6331: Algorithms Steve Lai Dynamic Programming Reading: CLRS Chapter 5 & Section 25.2 CSE 633: Algorithms Steve Lai Optimization Problems Problems that can be solved by dynamic programming are typically optimization problems. Optimization

More information

Chapter 5 Divide and Conquer

Chapter 5 Divide and Conquer CMPT 705: Design and Analysis of Algorithms Spring 008 Chapter 5 Divide and Conquer Lecturer: Binay Bhattacharya Scribe: Chris Nell 5.1 Introduction Given a problem P with input size n, P (n), we define

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

1 Examples of Weak Induction

1 Examples of Weak Induction More About Mathematical Induction Mathematical induction is designed for proving that a statement holds for all nonnegative integers (or integers beyond an initial one). Here are some extra examples of

More information

Divide and conquer. Philip II of Macedon

Divide and conquer. Philip II of Macedon Divide and conquer Philip II of Macedon Divide and conquer 1) Divide your problem into subproblems 2) Solve the subproblems recursively, that is, run the same algorithm on the subproblems (when the subproblems

More information

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016 CS125 Lecture 4 Fall 2016 Divide and Conquer We have seen one general paradigm for finding algorithms: the greedy approach. We now consider another general paradigm, known as divide and conquer. We have

More information

CS 4424 Matrix multiplication

CS 4424 Matrix multiplication CS 4424 Matrix multiplication 1 Reminder: matrix multiplication Matrix-matrix product. Starting from a 1,1 a 1,n A =.. and B = a n,1 a n,n b 1,1 b 1,n.., b n,1 b n,n we get AB by multiplying A by all columns

More information

The Fast Fourier Transform. Andreas Klappenecker

The Fast Fourier Transform. Andreas Klappenecker The Fast Fourier Transform Andreas Klappenecker Motivation There are few algorithms that had more impact on modern society than the fast Fourier transform and its relatives. The applications of the fast

More information

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 20: Dynamic Programming

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 20: Dynamic Programming CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 20: Dynamic Programming DYNAMIC PROGRAMMING Dynamic programming is an algorithmic paradigm in which

More information

Polynomial Functions. Linear Graphs and Linear Functions 1.3

Polynomial Functions. Linear Graphs and Linear Functions 1.3 Polynomial Functions Linear Graphs and Linear Functions 1.3 Forms for equations of lines (linear functions) Ax + By = C Standard Form y = mx +b Slope-Intercept (y y 1 ) = m(x x 1 ) Point-Slope x = a Vertical

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

Note that r = 0 gives the simple principle of induction. Also it can be shown that the principle of strong induction follows from simple induction.

Note that r = 0 gives the simple principle of induction. Also it can be shown that the principle of strong induction follows from simple induction. Proof by mathematical induction using a strong hypothesis Occasionally a proof by mathematical induction is made easier by using a strong hypothesis: To show P(n) [a statement form that depends on variable

More information

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version)

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version) CS 470/570 Divide-and-Conquer Format of Divide-and-Conquer algorithms: Divide: Split the array or list into smaller pieces Conquer: Solve the same problem recursively on smaller pieces Combine: Build the

More information

Midterm Exam 2 Solutions

Midterm Exam 2 Solutions Algorithm Design and Analysis November 12, 2010 Pennsylvania State University CSE 565, Fall 2010 Professor Adam Smith Exam 2 Solutions Problem 1 (Miscellaneous). Midterm Exam 2 Solutions (a) Your friend

More information

MAKING A BINARY HEAP

MAKING A BINARY HEAP CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.uc sd.edu Office 4208 CSE Building Lecture 19: Divide and Conquer Design examples/dynamic Programming MAKING A BINARY HEAP Base case. Break

More information

Chapter 6. Weighted Interval Scheduling. Dynamic Programming. Algorithmic Paradigms. Dynamic Programming Applications

Chapter 6. Weighted Interval Scheduling. Dynamic Programming. Algorithmic Paradigms. Dynamic Programming Applications lgorithmic Paradigms hapter Dynamic Programming reedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into sub-problems, solve each

More information

Chapter 5.3: Series solution near an ordinary point

Chapter 5.3: Series solution near an ordinary point Chapter 5.3: Series solution near an ordinary point We continue to study ODE s with polynomial coefficients of the form: P (x)y + Q(x)y + R(x)y = 0. Recall that x 0 is an ordinary point if P (x 0 ) 0.

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 14 Divide and Conquer Fast Fourier Transform Sofya Raskhodnikova 10/7/2016 S. Raskhodnikova; based on slides by K. Wayne. 5.6 Convolution and FFT Fast Fourier Transform:

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 5 Divide and Conquer: Fast Fourier Transform Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms

More information

Mat 3770 Bin Packing or

Mat 3770 Bin Packing or Basic Algithm Spring 2014 Used when a problem can be partitioned into non independent sub problems Basic Algithm Solve each sub problem once; solution is saved f use in other sub problems Combine solutions

More information

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary Complexity Analysis Complexity Theory Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary Output TRUE or FALSE Time and Space

More information

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101 A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),

More information

Analysis of Algorithms I: All-Pairs Shortest Paths

Analysis of Algorithms I: All-Pairs Shortest Paths Analysis of Algorithms I: All-Pairs Shortest Paths Xi Chen Columbia University The All-Pairs Shortest Paths Problem. Input: A directed weighted graph G = (V, E) with an edge-weight function w : E R. Output:

More information

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication Integer multiplication Say we have 5 baskets with 8 apples in each How do we determine how many apples we have? Count them all? That would take

More information

Divide and Conquer algorithms

Divide and Conquer algorithms Divide and Conquer algorithms Another general method for constructing algorithms is given by the Divide and Conquer strategy. We assume that we have a problem with input that can be split into parts in

More information

Dynamic Programming. Cormen et. al. IV 15

Dynamic Programming. Cormen et. al. IV 15 Dynamic Programming Cormen et. al. IV 5 Dynamic Programming Applications Areas. Bioinformatics. Control theory. Operations research. Some famous dynamic programming algorithms. Unix diff for comparing

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I 6. DYNAMIC PROGRAMMING I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013

More information

Partha Sarathi Mandal

Partha Sarathi Mandal MA 252: Data Structures and Algorithms Lecture 32 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The All-Pairs Shortest Paths Problem

More information

MAKING A BINARY HEAP

MAKING A BINARY HEAP CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.uc sd.edu Office 4208 CSE Building Lecture 19: Divide and Conquer Design examples/dynamic Programming MAKING A BINARY HEAP Base case. Break

More information

Approximation theory

Approximation theory Approximation theory Xiaojing Ye, Math & Stat, Georgia State University Spring 2019 Numerical Analysis II Xiaojing Ye, Math & Stat, Georgia State University 1 1 1.3 6 8.8 2 3.5 7 10.1 Least 3squares 4.2

More information

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi.

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi. How to ultiply Slides by Kevin Wayne. Copyright 5 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials Complex ultiplication Complex multiplication. a + bi) c + di) = x + yi.

More information

1.2. Indices. Introduction. Prerequisites. Learning Outcomes

1.2. Indices. Introduction. Prerequisites. Learning Outcomes Indices 1.2 Introduction Indices, or powers, provide a convenient notation when we need to multiply a number by itself several times. In this Section we explain how indices are written, and state the rules

More information

Shortest paths with negative lengths

Shortest paths with negative lengths Chapter 8 Shortest paths with negative lengths In this chapter we give a linear-space, nearly linear-time algorithm that, given a directed planar graph G with real positive and negative lengths, but no

More information

Discrete Math, Spring Solutions to Problems V

Discrete Math, Spring Solutions to Problems V Discrete Math, Spring 202 - Solutions to Problems V Suppose we have statements P, P 2, P 3,, one for each natural number In other words, we have the collection or set of statements {P n n N} a Suppose

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

Limits at Infinity. Horizontal Asymptotes. Definition (Limits at Infinity) Horizontal Asymptotes

Limits at Infinity. Horizontal Asymptotes. Definition (Limits at Infinity) Horizontal Asymptotes Limits at Infinity If a function f has a domain that is unbounded, that is, one of the endpoints of its domain is ±, we can determine the long term behavior of the function using a it at infinity. Definition

More information

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication The divide-and-conquer strategy solves a problem by: Chapter 2 Divide-and-conquer algorithms 1 Breaking it into subproblems that are themselves smaller instances of the same type of problem 2 Recursively

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 18 Prof. Erik Demaine Negative-weight cycles Recall: If a graph G = (V, E) contains a negativeweight cycle, then some shortest paths may not exist.

More information

Fast integer multiplication

Fast integer multiplication Fast integer multiplication David Harvey, Joris van der Hoeven, Grégoire Lecerf CNRS, École polytechnique Bordeaux, February 2, 2015 http://www.texmacs.org Fundamental complexities I(n): multiplication

More information

Lecture 20: Discrete Fourier Transform and FFT

Lecture 20: Discrete Fourier Transform and FFT EE518 Digital Signal Processing University of Washington Autumn 2001 Dept of Electrical Engineering Lecture 20: Discrete Fourier Transform and FFT Dec 10, 2001 Prof: J Bilmes TA:

More information

Space- and Time-Efficient Polynomial Multiplication

Space- and Time-Efficient Polynomial Multiplication Space- and Time-Efficient Polynomial Multiplication Daniel S. Roche Symbolic Computation Group School of Computer Science University of Waterloo ISSAC 2009 Seoul, Korea 30 July 2009 Univariate Polynomial

More information

Chakravala - a modern Indian method. B.Sury

Chakravala - a modern Indian method. B.Sury Chakravala - a modern Indian method BSury Indian Statistical Institute Bangalore, India sury@isibangacin IISER Pune, India Lecture on October 18, 2010 1 Weil Unveiled What would have been Fermat s astonishment

More information

Disjoint paths in tournaments

Disjoint paths in tournaments Disjoint paths in tournaments Maria Chudnovsky 1 Columbia University, New York, NY 10027, USA Alex Scott Mathematical Institute, University of Oxford, 24-29 St Giles, Oxford OX1 3LB, UK Paul Seymour 2

More information

Dynamic Programming( Weighted Interval Scheduling)

Dynamic Programming( Weighted Interval Scheduling) Dynamic Programming( Weighted Interval Scheduling) 17 November, 2016 Dynamic Programming 1 Dynamic programming algorithms are used for optimization (for example, finding the shortest path between two points,

More information

CSE 421 Introduction to Algorithms Final Exam Winter 2005

CSE 421 Introduction to Algorithms Final Exam Winter 2005 NAME: CSE 421 Introduction to Algorithms Final Exam Winter 2005 P. Beame 14 March 2005 DIRECTIONS: Answer the problems on the exam paper. Open book. Open notes. If you need extra space use the back of

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 22 All-Pairs Shortest Paths Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 All Pairs

More information

Dynamic Programming. Prof. S.J. Soni

Dynamic Programming. Prof. S.J. Soni Dynamic Programming Prof. S.J. Soni Idea is Very Simple.. Introduction void calculating the same thing twice, usually by keeping a table of known results that fills up as subinstances are solved. Dynamic

More information

MATH 304 Linear Algebra Lecture 8: Vector spaces. Subspaces.

MATH 304 Linear Algebra Lecture 8: Vector spaces. Subspaces. MATH 304 Linear Algebra Lecture 8: Vector spaces. Subspaces. Linear operations on vectors Let x = (x 1, x 2,...,x n ) and y = (y 1, y 2,...,y n ) be n-dimensional vectors, and r R be a scalar. Vector sum:

More information

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 8

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 8 CS 70 Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 8 Polynomials Polynomials constitute a rich class of functions which are both easy to describe and widely applicable in

More information

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem Chapter 2. Divide-and-conquer algorithms The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem. 2. Recursively

More information

Implementation of the DKSS Algorithm for Multiplication of Large Numbers

Implementation of the DKSS Algorithm for Multiplication of Large Numbers Implementation of the DKSS Algorithm for Multiplication of Large Numbers Christoph Lüders Universität Bonn The International Symposium on Symbolic and Algebraic Computation, July 6 9, 2015, Bath, United

More information

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication 1 Introduction We have now seen that the Fast Fourier Transform can be applied to perform polynomial multiplication

More information

FFT: Fast Polynomial Multiplications

FFT: Fast Polynomial Multiplications FFT: Fast Polynomial Multiplications Jie Wang University of Massachusetts Lowell Department of Computer Science J. Wang (UMass Lowell) FFT: Fast Polynomial Multiplications 1 / 20 Overview So far we have

More information

feb abhi shelat Matrix, FFT

feb abhi shelat Matrix, FFT L7 feb 11 2016 abhi shelat Matrix, FFT userid: = Using the standard method, how many multiplications does it take to multiply two NxN matrices? cos( /4) = cos( /2) = sin( /4) = sin( /2) = Mergesort Karatsuba

More information

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,.

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,. lgorithmic Paradigms hapter Dynamic Programming reed Build up a solution incrementally, myopically optimizing some local criterion Divide-and-conquer Break up a problem into two sub-problems, solve each

More information

Reductions, Recursion and Divide and Conquer

Reductions, Recursion and Divide and Conquer Chapter 5 Reductions, Recursion and Divide and Conquer CS 473: Fundamental Algorithms, Fall 2011 September 13, 2011 5.1 Reductions and Recursion 5.1.0.1 Reduction Reducing problem A to problem B: (A) Algorithm

More information

Time-bounded computations

Time-bounded computations Lecture 18 Time-bounded computations We now begin the final part of the course, which is on complexity theory. We ll have time to only scratch the surface complexity theory is a rich subject, and many

More information

Chapter 4 Divide-and-Conquer

Chapter 4 Divide-and-Conquer Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication Matrix Multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. n c ij = a ik b kj k=1 c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn = a 11 a 12 a 1n

More information

shelat 16f-4800 sep Matrix Mult, Median, FFT

shelat 16f-4800 sep Matrix Mult, Median, FFT L5 shelat 16f-4800 sep 23 2016 Matrix Mult, Median, FFT merge-sort (A, p, r) if p

More information

Today s topics. Algorithms. University of Washington Course. Text books. Analyzing the course and content. Course overview

Today s topics. Algorithms. University of Washington Course. Text books. Analyzing the course and content. Course overview Today s topics Algorithms Richard Anderson University of Washington Teaching Algorithms Active Learning in Algorithms Big Ideas: Solving Problems in Practice Mysore / Theory Discussion 1 2 Text books University

More information

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution.

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution. Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer.! Break up problem into several parts.! Solve each part recursively.! Combine solutions to sub-problems into overall solution. Most common

More information

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk CMPS 2200 Fall 2017 Divide-and-Conquer Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 The divide-and-conquer design paradigm 1. Divide the problem (instance)

More information

2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G.

2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G. CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh (rezab@stanford.edu) HW#1 Due at the beginning of class Thursday 01/21/16 1. Prove that at least one of G and G is connected. Here, G

More information

Fast Fourier Transform

Fast Fourier Transform Why Fourier Transform? Fast Fourier Transform Jordi Cortadella and Jordi Petit Department of Computer Science Polynomials: coefficient representation Divide & Conquer Dept. CS, UPC Polynomials: point-value

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common

More information

The Knapsack Problem. 28. April /44

The Knapsack Problem. 28. April /44 The Knapsack Problem 20 10 15 20 W n items with weight w i N and profit p i N Choose a subset x of items Capacity constraint i x w i W wlog assume i w i > W, i : w i < W Maximize profit i x p i 28. April

More information

On the Exponent of the All Pairs Shortest Path Problem

On the Exponent of the All Pairs Shortest Path Problem On the Exponent of the All Pairs Shortest Path Problem Noga Alon Department of Mathematics Sackler Faculty of Exact Sciences Tel Aviv University Zvi Galil Department of Computer Science Sackler Faculty

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lectures 15-16 Dynamic Programming Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

The Divide-and-Conquer Design Paradigm

The Divide-and-Conquer Design Paradigm CS473- Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm CS473 Lecture 4 1 The Divide-and-Conquer Design Paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 /9/ lgorithmic Paradigms hapter Dynamic Programming reed. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into two sub-problems, solve

More information

CS173 Running Time and Big-O. Tandy Warnow

CS173 Running Time and Big-O. Tandy Warnow CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review

More information

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction CSC 344 Algorithms and Complexity Lecture #1 Review of Mathematical Induction Proof by Mathematical Induction Many results in mathematics are claimed true for every positive integer. Any of these results

More information