473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with Dijkstra's algorithm

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.


Dec 13 '05 #1
3 4992
Ook wrote:
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?).
comp.programming comes to mind as one option

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,
no

or should I select the next unused vertex adjacent to a used vertex that gives me the leasted cumulative weight?
yes

If the latter, then I should choose A-C for 6, then A-B-D for 7, and lastly A-B-E for 8.
Certaintly choose A-C for 6. Then you update the distances based on
having made that choice and choose the next closest item (which may be
A-B-D for 7 or may be something else which becomes closer by virtue of
the path through C).

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.
That is the basic idea of the algorithm. (But bear in mind that it
doesn't work if any edge has negative length.)


Dec 13 '05 #2
comp.programming comes to mind as one option
Thanks, I'll try there :)
or should I select the next unused vertex adjacent to a
used vertex that gives me the leasted cumulative weight?


yes


That is what I was missing. Most of the explanations I've seen seem to
assume you already know how it works, and don't clearly explain it. :P
Dec 13 '05 #3
Matthew L Reed wrote:
comp.programming comes to mind as one option

Thanks, I'll try there :)

or should I select the next unused vertex adjacent to a
used vertex that gives me the leasted cumulative weight?


yes

That is what I was missing. Most of the explanations I've seen seem to
assume you already know how it works, and don't clearly explain it. :P


I'd say find a better explanation, as there are good ones out there.
"Introduciton to Algorithms" by Cormen et al. is one example.
Dec 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Herman | last post by:
Hi everyone, I'm implementing Dijkstra's algorithm for a class project, and I'm having trouble compiling the class that runs the algorithm. All of the other files compile fine except for this one....
6
by: ThanhVu Nguyen | last post by:
Hi all, I need recommendation for a very fast shortest path algorithm. The edges are all directed, positive weights. Dijkstra shortest path will solve it just fine but the if the graph is not...
3
by: A_StClaire_ | last post by:
implemented Dijkstra's algorithm as follows. plz pour on the negative criticism cuz I know I have a ton to learn. oh, before you flame me regarding the language, my class was told to do this in...
5
by: A_StClaire_ | last post by:
thoughts or criticism anyone? using System; namespace Dijkstra { public class Algorithm { private const int nodes = 10;
1
by: arlef | last post by:
Can somebody please explain and provide pseudocode for the Dijkstra algorithm? I'm trying to implement the Dijkstra shortest path algorithm. However, I'm finding it extremely difficult to...
9
by: Josh Zenker | last post by:
I've been working on an implementation of Dijkstra's algorithm on and off for the past few days. I thought I was close to being finished, but clearly I've done something wrong. I'm not a very...
8
by: abhradwip | last post by:
I want to write a program which will find the shortest path between n no. of cities using dijkstra's algorithm ...... but could not do it..... i have written a program which will give the shortest...
2
by: shashankbs | last post by:
Given a topology and a certain node X, find the shortest path tree with X as the root. * Input: a topology file similar to the following (which is a three-node ring) ...
1
by: Glenton | last post by:
Hi All Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm: #!/usr/bin/env python #This is meant to solve a maze with Dijkstra's...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.