computer science - An example of Dijkstra's algorithm to fail with one negative edge -


i'm trying think of graph edges have positive weights, except of 1 edge such dijkstra's algorithm fails produce correct output.

i'd glad idea.

edit:
i've seen graph counter-example don't understand why. vertex a last pop-out queue , relax() edge a->e. path s->a->e chosen, correct path (and not s->b->e claimed)

enter image description here

thanks

dijkstra terminates upon expanding goal node. use priority queue in dijkstra (not queue) expand node has least cost. in example never expanded.

  open list = [ s cost:0 ] // priortiy queue pop s out of open list   closed list = [ s cost:0 ]   open list = [ b cost:1 ; cost:5 ] pop b out of open list   closed list = [ s cost:0 ; b cost:1 ]   open list = [ e cost:2 ; cost:5 ] pop e out of open list // it's better terminate when reach goal if don't // doesn't make difference going find shortest path // other nodes    closed list = [ s cost:0 ; b cost:1 ; e cost:2 ]    open list = [ cost:5 ] pop out of open list    // there isn't nodes can push open list    closed list = [ s cost:0 ; b cost:1 ; e cost:2 ; cost:5 ]    open_list = [] 

dijkstra push node closed list upon expanding because assumes has find shortest path it. if don't terminate upon reaching goal never expand because in our closed list.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -