I am trying to find out if it is possible to use Dijkstra\'s algorithm to find the longest path in a directed acyclic path. I know that it is not possible to find the longes
Not enough reputation to comment on @punkyduck's answer, but I'd like to mention that replacing min
with max
in the DAG
a ——2——→ b ——2——→ c
│ ↑
│ │
1 4
│ │
└——————→ d ———————┘
actually works, as the algorithm will
a
⇨ ab=2, ad=1
⇨ l(b)=(ab,2), l(d)=(ad,1)
b
since we use max
⇨ abc=2
⇨ l(c)=(abc,2)
c
since abc>ad
⇨ Nothing happensd
⇨ adc=5
⇨ update l(c)=(adc,5)
So at the last step the correct longest path adc
is found. Just to point out the mistake.