Applying Dijkstra Algorithm: Solving a Problem

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary
SUMMARY

The discussion focuses on the application of Dijkstra's algorithm to find the shortest path in a graph. The algorithm initializes values for each vertex, utilizes a priority queue for efficient extraction of the minimum, and applies relaxation to update path costs. The user initially confused minimum spanning trees with shortest path calculations, clarifying that Dijkstra's algorithm is applicable to both directed and undirected graphs. The final conclusion confirms that the first graph correctly represents the shortest paths from the source node, with a total weight of 23.

PREREQUISITES
  • Understanding of Dijkstra's algorithm and its implementation
  • Familiarity with graph theory concepts, including vertices and edges
  • Knowledge of priority queues and their role in algorithm efficiency
  • Ability to perform graph relaxation techniques
NEXT STEPS
  • Study the implementation of Dijkstra's algorithm in Python using libraries like NetworkX
  • Explore the differences between Dijkstra's algorithm and Prim's algorithm for minimum spanning trees
  • Learn about graph representation techniques, such as adjacency lists and matrices
  • Investigate the use of Dijkstra's algorithm in real-world applications, such as GPS navigation systems
USEFUL FOR

Students, software developers, and data scientists interested in algorithm design, graph theory, and optimization techniques will benefit from this discussion.

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: 125
  • dijkstra.png
    dijkstra.png
    3.2 KB · Views: 113
  • dijkstra.png
    dijkstra.png
    3.6 KB · Views: 128
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 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K