5 10 2 mtp simple recursive algorithm 2 0 0 18 22

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: j) y MT(i, j - 1) + weight of the edge from (i, j - 1) to (i, j) return max(x,y) 5 5 2 M T ( i, j ) 5 1 3 promising start, but leads to bad choices! 5 10 2 MTP: Simple Recursive Algorithm 2 0 0 18 22 sink MTP: Dynamic Programming MTP: Dynamic Programming j Fill out a table s using the recurrence relation: 1 1 0 i 1 S0,1 = 1 5 si-1, j + weight of the edge between (i-1, j) and (i, j) si, j = max 0 source 1 si, j-1 + weight of the edge between (i, j-1) and (i, j) 5 S1,0 = 5 The running time is n x m for an n by m grid •  Calculate optimal path score for each vertex in the graph (n = # of rows, m = # of columns) •  Each vertex’s score is the maximum of the prior vertices score plus the weight of the respective edge in between MTP: Dynamic Programming (cont’d) MTP: Dynamic Programming (cont’d) j j 0 source 1 1 0 i 3 2 1 5 3 8 S2,0 = 8 0 source 2 1 5 2 2 1 1 0 3 S0,2 = 3 i 10 8 S3,0 = 8 1 5 7 5 3 13 S1,2 = 13 2 2 8 0 3 5 3 3 2 1 3 2 1 5 7 S1,1 = 4 2 12 S2,1 = 12 8 S3,0 = 8 6 MTP: Dynamic Programming (cont’d) MTP: Dynamic Programming (cont’d) j 1 2 1 0 i j 0 source 2 3 3 2 1 13 5 12 0 8 3 12 S3,1 = 12 MTP: Dynamic Programming (cont’d) j 0 source 1 1 0 i 5 3 10 2 13 16 0 8 (showing all back-traces) 16 0 5 0 20 S2,3 = 20 0 8 12 21 S3,2 = 21 Manh...
View Full Document

Ask a homework question - tutors are online