Dijkstra and A* Algorithms: Why is A* faster?

enter image description here

I am learning about Dijkstra’s Algorithm and the A* Algorithm and I have manually worked through the graph attached here, which is supposed (I think) to demonstrate that the A* Algorithm is faster than the Dijkstra one. The sequence in which I chose the nodes is indicated by the circled numbers. I can see that the process is fairly simple but there are plenty of possibilities for human error, so please bear with me.

My course book says that the A* will be quicker.

I can’t see why this is true. Have I worked through the graph incorrectly?

It seems to me that both methods require that all nodes must be visited so where is the increase in efficiency?

I have read what I can on Stack Overflow about this so please don’t point me at earlier posts unless there is a very good reason.

Dijkstra same weight but different edges [closed]

I read about Djikstra’s algorithm and I want to be sure about two fundamental things, would appreciate if you could answer me mathematically so I can understand how words are translated to math so I can use it in other uses as well.

so here are my questions:

  1. if we mark the shortest path Djikstra’s algorithm found in some network with $ n$ stations in some topological construction: does it necessarily find the shortest path between each pair of vertices?
  2. assume there’s at least an additional path, somewhere from $ s$ to $ t$ , with same weight but with different edges (meaning both paths don’t have a common edge), how can we find this edge?

I don’t understand it well and I will really appreciate explanation so I can understand it better.

Watched videos, read materials online, and tried to concise what I am not sure about so I can request it here to deepen my understanding.

thank you for your time and assistance

Dijkstra shortest path yields unintuitive results

Considering the following nodes with edge weights in red, Dijkstra’s shortest path algorithm seems to return incorrect results, at least by the definition of the steps on wikipedia. By those rules, the distance from 0 to 2 will be calculated by passing through 1 instead of 3.

The final distances (from 0) would come out to:

0 -> 0

1 -> 0.2

2 -> 1000.2

3 -> 0.5

The weights in this case are bi-directional but I don’t see a way for information of the connection between 2 and 3 to ever affect the final distance between 0 and 2. Am I missing something about the limitations of this algorithm on this type of graph or are the steps listed incorrect?

example cycle

How can i modify Dijkstra algorithm for equal situation?

I have a question below

In Dijkstra’s Algorithm, if there is more than one possible shortest path from u to any vertex v, any one of the paths can be the output of the algorithms as a shortest path. Assume now that if that is the case for any vertex v, i.e.there are many paths of the same minimum weight, you want to find the path with minimum number of edges. If there are stil ties then they can now be broken arbitrarily. Describe how to modify Dijkstra’s Algorithm to solve this problem

Dijkstra without decrease key

I was reading though this paper, which suggests using dijkstra without edge relaxation, but to rather to just insert new nodes, cf page 16 for the pseudo code. But to me the code looks wrong. I think the comparison should be

k <= d[u] 

and also the update of the d[u] in the next line seems redundant to me. I think the delete-min operation can never return a vertex with distance label k which is strictly less than d[u] since whenever a vertex distance pair is inserted into the priority queue the distance array d is updated. Am I correct in assuming that this is a mistake in the paper?

C++ finding the shortest path, reducing time complexity, dijkstra v Floyd Warshall Algorithm?

I have an algorithm that I am performing on a graph and I am looking to do an analysis of how to speed it up and would appreciate any comments.

The algorithm iterates over every edge in the graph.

For each edge it (1) finds the shortest path from the input node of the graph to the source node of the edge (Task 1).

It then (2) finds the shortest path from the sink node of the edge to output node of the graph (Task 2).

Doing this process for every edge is what is causing it to be slow.

I am currently using dijkstra’s algorithm implemented with using priority queues in C++ to find the shorest paths. According to this website the complexity of this is O(ELogV)).

There are a couple of ways that I think I could improve this.

  1. There is a lot of redundant calculation going on. Once I’ve found the shortest path from a node to the output for example (Task 2), I know the shortest path for every node along the path from the node where I started. I am wondering what is an efficient way to implement this, which C++ STL containers to use? Is there anyway to estimate the decrease in complexity?

  2. A different approach would be to use Floyd Warshall Algorithm which finds the shortest distances between every pair of vertices in a DAG. The complexity of this is O(V^3). Would it then be quicker to look this information up when computing the shortest paths? How could I quantify how much faster this approach is.

A* without heuristic more efficient than Dijkstra

I am using the module networkx to operate on graphs made from OpenStreetMap. I wanted to compare the shortest path algorithm to find wich one is faster, and I compared Dijkstra and A*. The problem is : A* is most of the time faster than Dijkstra eventhough I didn’t defined any heuristic function. I understood that A* with h=0 was equivalent to Dijkstra, then why is it not the same time? Thank you in advance for your answers !

Simples Implementação em algoritmo de Dijkstra

Olá, Galera estou com uma pequena dúvida. Nessa implementação é aplicado o algoritmo de Dijkstra, que retorna os caminhos de menor custos. Porém ele está retornando todos do caminhos de menor custo, e eu precisaria somente do caminho de menor custo dos vértices 0 a 3. Alguém saberia como implementar essa pequena solução. obs:(Esse é um grafo orientado)

    #include<stdio.h>     #define QTD 9999     #define MAX 5      void dijkstra(int G[MAX][MAX],int n,int inicial);      int main()     {         int i,j,u,l,p;         int G[MAX][MAX];          for(l=0 ;l < MAX; l++)         {             for( p=0; p< MAX; p++)             {                 G[l][p] = -1;             }         }          G[0][1]=100;         G[0][2]=800;         G[1][3]=500;         G[1][4]=700;         G[2][1]=200;         G[2][3]=500;         G[4][3]=100;          for(l=0 ;l < MAX; l++)         {             for( p=0; p< MAX; p++)             {                 printf("%d,",G[l][p]);             }             printf("\n");         }          printf("\nInforme o node inicial:");         scanf("%d",&u);         dijkstra(G,MAX,u);          return 0;     }      void dijkstra(int G[MAX][MAX],int n,int inicial)     {          int custo[n][n],distancia[n],pred[n];         int visitado[n],cont,distanciamin,proxno,i,j;           for(i=0;i<n;i++)             for(j=0;j<n;j++)                 if(G[i][j]==-1)                     custo[i][j]=QTD;                 else                     custo[i][j]=G[i][j];          for(i=0;i<n;i++)         {             distancia[i]=custo[inicial][i];             pred[i]=inicial;             visitado[i]=0;         }          distancia[inicial]=0;         visitado[inicial]=1;         cont=1;          while(cont<n-1)         {             distanciamin=QTD;               for(i=0;i<n;i++)                 if(distancia[i]<distanciamin&&!visitado[i])                 {                     distanciamin=distancia[i];                     proxno=i;                 }              //verifica se existe melhor caminho atraves do proximo node             visitado[proxno]=1;             for(i=0;i<n;i++){                 if(!visitado[i])                     if(distanciamin+custo[proxno][i]<distancia[i])                     {                         distancia[i]=distanciamin+custo[proxno][i];                         pred[i]=proxno;                     }             }             cont++;         }          //imprime o caminho e a distancia de cada node         for(i=0;i<n;i++)             if(i!=inicial)             {                 printf("\nDistancia do no%d=%d",i,distancia[i]);                 printf("\nCaminho=%d",i);                  j=i;                 do                 {                     j=pred[j];                     printf("<-%d",j);                 }while(j!=inicial);         }     } 

What is the space complexity of Dijkstra Algorithm?

As per my understanding. The space complexity will be O(V). An array of V nodes will be created which in turn be used to create the Min heap.

But this link is stating that It is O(V^2)? I don’t understand how it can be O(V^2)?

I have search the same topic in the Book entitled Introduction_to_Algorithms by Thomas H. Cormen but still not able to find the answer. I Don’t understand what I am missing.