MHB Applying Dijkstra Algorithm: Solving a Problem

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I want to apply the Dijkstra algorithm at an example.

Code:
Dijkstra(G,s,v)
1. InitialValues(G,s)
2.S<-∅
3.Q<-V // priority queue,with key the field d[]
4. while Q  ≠ ∅
5.         u<-Extraction_of_Minimum(Q)
6.          S<-S U {u}
7.          for each v ∈ Adj[u]
8.               Relaxation(u,v,w)

Code:
InitialValues(G,s)
 for each v ∈ V
      d[v]<-oo
      p[v]<-∅
 d[s]<-0

Code:
Relaxation(u,v,w)
 if d[v]>d[u]+w(u,v)
    d[v]<-d[u]+w(u,v)
    p[v]<-u

This is the given graph:

View attachment 3127

Executing the algorithm,I found the following:

$$p[a]=s$$
$$p[c]=s$$
$$p=c$$
$$p[d]=a$$

So,the tree,that we get from the Dijkstra's algorithm would be:

View attachment 3128

So,the weight would be $23$.

But...I found the following tree,with less weight:

View attachment 3129

Have I done something wrong,applying the algorithm? (Thinking)
 

Attachments

  • dijkstra.png
    dijkstra.png
    6.2 KB · Views: 106
  • dijkstra.png
    dijkstra.png
    3.2 KB · Views: 99
  • dijkstra.png
    dijkstra.png
    3.6 KB · Views: 112
Last edited:
Physics news on Phys.org
According to definition, the minimum spanning tree is applied on a connected undirected graph.

So first convert the directed graph to undirected then apply the alogrithm to find the minimum spanning tree.

I'm not sure if there is a version for a directed graph because if you look at the last graph if you move from $$s$$ then you are stuck.
 
ZaidAlyafey said:
According to definition, the minimum spanning tree is applied on a connected undirected graph.

So first convert the directed graph to undirected then apply the alogrithm to find the minimum spanning tree.

I'm not sure if there is a version for a directed graph because if you look at the last graph if you move from $$s$$ then you are stuck.

I am sorry..I don't want to find the minimum spanning tree.. (Blush)

I wanted to apply the Dijkstra's algorithm at the above example..

So,I have to find a path,that contains all the vertices , such that the sum of the weights of its constituent edges is minimized..right?

So..have I done something wrong? (Thinking)
 
Dijkstra's algorithm is used to determine the lowest cost path from a given node (the source) $s$ to every other node in the graph. (The graph may be directed or undirected, since an undirected path can be viewed as two opposing directed path with the same weight.)

In the last graph provided, your directed path tree from $s$ can only reach $c$. The cost going from $s$ to $a$ in that path tree in fact is $\infty$ as it is not reachable, but that's not the case.
 
magneto said:
Dijkstra's algorithm is used to determine the lowest cost path from a given node (the source) $s$ to every other node in the graph. (The graph may be directed or undirected, since an undirected path can be viewed as two opposing directed path with the same weight.)

In the last graph provided, your directed path tree from $s$ can only reach $c$. The cost going from $s$ to $a$ in that path tree in fact is $\infty$ as it is not reachable, but that's not the case.

A ok..so is the first graph right? (Thinking)
 
evinda said:
A ok..so is the first graph right? (Thinking)

Yes. It gives the shortest path of $\enclose{circle}{s}$ to each of the other nodes. (Wasntme)
 
I like Serena said:
Yes. It gives the shortest path of $\enclose{circle}{s}$ to each of the other nodes. (Wasntme)

Nice...thank you very much! (Mmm)
 

Similar threads

Replies
2
Views
2K
Replies
8
Views
2K
Replies
11
Views
3K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
5
Views
944
Back
Top