java - Directed graph with non negative weights (adjacency matrix) -
first off, apologize bad paint drawing of graph. weights not scaled. having hard time coming algorithms solve few problems.
first, want find paths take 3 "stops" or less c c (just example... can 2 vertexes). after researching, found bfs might i'm looking solve problem. correct in assumption?
there 2 paths have 3 stops or less:
c -> d -> c
c -> e -> b -> c
i want find shortest path c (just example.. can 2 vertexes). after doing little bit of research, came conclusion should use dijkstra's algorithm. correct in assumption? if so, saw there various implementations. matter if use binary heap, fibonacci heap, or queue?
thank , please let me know if need more information!
first, want find paths take 3 "stops" or less c c (just example... can 2 vertexes). after researching, found bfs might i'm looking solve problem. correct in assumption?
yes, are. property of bfs processes nodes in level-order, therefore first process nodes neighbors of source node, nodes neighbors of neighbors of source node etc.
i want find shortest path c (just example.. can 2 vertexes). after doing little bit of research, came conclusion should use dijkstra's algorithm. correct in assumption? if so, saw there various implementations. matter if use binary heap, fibonacci heap, or queue?
again, yes, dijkstra's algorithm classic solution such problems. there other algorithms better suited special situations (e.g. bellman-ford if have negative weights in graph), in cases (yours well), go dijkstra. regarding implementation, theoretically best implementation based on min-priority queue implemented fibonacci heap. running time of implementation o(|e|+|v|/log|v|)
(where |v|
number of vertices , |e|
number of edges). however, in practice, binary heaps outperform fibonacci heaps, see this interesting thread more information.
Comments
Post a Comment