Applying Dijkstra Algorithm: Solving a Problem

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

Discussion Overview

The discussion revolves around the application of Dijkstra's algorithm to a specific graph example, with participants exploring the algorithm's functionality, its applicability to directed versus undirected graphs, and the interpretation of results. The focus includes theoretical understanding and practical implementation of the algorithm.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant outlines the steps of Dijkstra's algorithm and presents results from applying it to a graph, questioning the validity of their findings due to discrepancies in the resulting tree weight.
  • Another participant asserts that Dijkstra's algorithm is meant for finding the minimum spanning tree on undirected graphs and suggests converting directed graphs to undirected ones for this purpose.
  • A later reply clarifies that Dijkstra's algorithm is intended to find the shortest path from a source node to all other nodes, regardless of graph directionality, but notes that some nodes may be unreachable.
  • Participants discuss the implications of the directed graph's structure on the results, particularly regarding reachability and path costs.
  • There is a confirmation that the initial graph analysis was correct in finding the shortest paths from the source node to other nodes.

Areas of Agreement / Disagreement

Participants express differing views on the applicability of Dijkstra's algorithm to directed versus undirected graphs, with some confusion about the purpose of the algorithm versus the minimum spanning tree concept. While there is some agreement on the correctness of the initial application of the algorithm, the discussion remains unresolved regarding the interpretation of the graph structure and reachability.

Contextual Notes

There are limitations in understanding the graph's structure and the assumptions about node reachability, which may affect the application of Dijkstra's algorithm. The discussion does not resolve these uncertainties.

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: 128
  • dijkstra.png
    dijkstra.png
    3.2 KB · Views: 116
  • dijkstra.png
    dijkstra.png
    3.6 KB · Views: 132
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
2K
  • · Replies 2 ·
Replies
2
Views
2K