O
Ook
This is probably a bit OT, as I'm not looking for a c++ implementaiton of
Dijkstra's algorithm, rather I'm just trying to understand it (is there a
better place then here to ask this question?). I've reviewed several sites
and the faq (no, I'm not asking you to do my homework for me) and the
examples don't give me the information I need to continue on. I'm working
with a complex tree, and am not sure how to logically apply Dijkstra's
algorithm to it. This is how I understand it in my own words:
Let's say I start at A, and the adjacent vertex with the least weight is
A-B, and the weight of the edge is 5.
A--5 --B
From here, there are only 3 places I can go as follows:
A--6--C
A--5--B--2--D
A--5--B--3--E
From A-C is 6, from A-B-D is 7, from A-B-E is 8. The next shortest path is
from A-C for a total of 6, not A-B-D or A-B-E.
D for a total of 7 or 8. Here is where I'm confused: does my second step
have to be a continuation of the first step, IOW can I only go from B to the
next unused vertex, or should I select the next unused vertex adjacent to a
used vertex that gives me the leasted cumulative weight? If the latter, then
I should choose A-C for 6, then A-B-D for 7, and lastly A-B-E for 8. At each
stop, I look at all adjacent nodes and fill in the lessor of the already
figured distance to the node, and the distance from the node I stopped at to
that node. If I do this, I eventually get what I believe is the shortest
path to my destination, but I'm not sure I did it right.
Dijkstra's algorithm, rather I'm just trying to understand it (is there a
better place then here to ask this question?). I've reviewed several sites
and the faq (no, I'm not asking you to do my homework for me) and the
examples don't give me the information I need to continue on. I'm working
with a complex tree, and am not sure how to logically apply Dijkstra's
algorithm to it. This is how I understand it in my own words:
Let's say I start at A, and the adjacent vertex with the least weight is
A-B, and the weight of the edge is 5.
A--5 --B
From here, there are only 3 places I can go as follows:
A--6--C
A--5--B--2--D
A--5--B--3--E
From A-C is 6, from A-B-D is 7, from A-B-E is 8. The next shortest path is
from A-C for a total of 6, not A-B-D or A-B-E.
D for a total of 7 or 8. Here is where I'm confused: does my second step
have to be a continuation of the first step, IOW can I only go from B to the
next unused vertex, or should I select the next unused vertex adjacent to a
used vertex that gives me the leasted cumulative weight? If the latter, then
I should choose A-C for 6, then A-B-D for 7, and lastly A-B-E for 8. At each
stop, I look at all adjacent nodes and fill in the lessor of the already
figured distance to the node, and the distance from the node I stopped at to
that node. If I do this, I eventually get what I believe is the shortest
path to my destination, but I'm not sure I did it right.