Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slight different solutions to shortest path

This is from the book Algorithm Design

This is from the book Algorithms

I first read this OPT formula from the book Algorithm Design(the first pic), I understand this very well I think, whether use i-1 edges or i edges leading to different OPT(i-1,v) or OPT(i-1,w)+Cvw.

However, when I read the same problem from the book Algorithms (the second pic starting from "In dynamic programming..."), I am confused because it eliminates the OPT(i-1,v), which means delete the condition that path P uses at most i-1 edges, and just using OPT(i-1,w)+Cvw. I was just wondering why this formula is still OK? Can someone explain?

like image 678
CSnerd Avatar asked Dec 05 '25 13:12

CSnerd


1 Answers

I believe that the distinction is in what the DP values mean. In the first case, the value means "the best path to v using at most i edges," and in the second the value means "the best path to v using exactly i edges." Given the second of these you can directly read off the answer by looking at the final DP value, whileas in the second you'd have to look at dp(v, 0), dp(v, 1), dp(v, 2), ... dp(v, n - 1).

Hope this helps!

like image 104
templatetypedef Avatar answered Dec 07 '25 18:12

templatetypedef