algorithm - Traversal of cities - is this case missing from the solution? -


warning: question requires initial effort understood

this question not duplicate of dynamic programming : traversal of cities. let's suppose have following graph 4 cities [0-3]:

  d[0][1] = 1;   d[0][2] = 2;   d[0][3] = 5;   d[1][2] = 3;   d[1][3] = 6;   d[2][3] = 4; 

the solution proposed in link is

c[i,j] = {    c[i,j-1] + d[j-1,j]                   (if < j-1)    min c[k,i] + d[k,j] 0 <= k <    (if = j-1) } 

but let's calculate c[1][2]:

c[1][2] = min between {            k = 0 => c[0,1] + d[0][2]           } 

this makes sense it not path evaluate @ step, since have grouped cities [0,1] first set , had [2] alone second set. in case have been

c[1][2] = min between {            k = 0 => c[0,1] + d[0][2]            d[0][1]           } 

at point i'd ask if objection makes sense @ all. in case did , algorithm proposed in link above wrong, how should include occurrence in solution? tried formulate recursively couldn't come simple.

the solution referring indeed incomplete , not account case when second traveler starts @ j. account that, update recurrent relation to:

c[i,j] = {    c[i,j-1] + d[j-1,j]                   (if < j-1)    min c[k,i] + d[k,j] 0 <= k <        , c[0,i]                        (if = j-1) } 

here exception c[0,1] should set d[0,1]

this way account case when second traveler started (c[0,i] cost of first traveler traveling 0 i, , there's no cost second traveler start @ j = i+1).

note can replace 0 <= k < i 0 < k < i, because k = 0 results in c[0,i] + d[0,j] strictly greater c[0,i]


Comments