This reminds me of "Dijkstra's Algorithm" from Further Maths 😂
👍︎ 22
💬︎
📅︎ Dec 19 2020
🚨︎ report
Trying to understand the complexity of the Dijkstra algorithm

Hello,

I am currently trying to understand the complexity of the Dijkstra algorithm. I understand the algorithm itself, however, am struggeling to comprehend how one can determine its complexity.
I know that it can reach different complexities, but am only looking into understanding the reasoning behind the complexity of O(|V|^2).

I am preferably looking for a detailed explanation.

Can anyone help? I am open to any kind of format- reddit comment, youtube videos, blogs, websites, etc.

👍︎ 22
💬︎
📅︎ Nov 30 2020
🚨︎ report
What is Dijkstra's Algorithm? seedbx.com/understanding-…
👍︎ 14
💬︎
📅︎ Dec 22 2020
🚨︎ report
I wish Chris Jordan would have studied Dijkstra's algorithm
👍︎ 121
💬︎
📅︎ Oct 19 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm youtu.be/-O-jQC6iHYE
👍︎ 230
📰︎ r/coding
💬︎
📅︎ Oct 18 2020
🚨︎ report
Would anyone be willing to take a look at my program and help me with implementing Dijkstra's algorithm into it? I'm really struggling lol

I've got a program so far that generates a maze from a grid in windows forms, but I've just hit a mind blank and don't know how I'd implement Dijkstra's into it. I can send screenshots or copy and paste my code, can't really put it here as its about 200 lines of code . Any help would be greatly appreciated

👍︎ 4
💬︎
👤︎ u/Nswl
📅︎ Nov 15 2020
🚨︎ report
Dijkstra's Algorithm Implementation

I am trying to implement Dijsktra's algorithm which will find the shortest path from one vertex to a given end vertex in a graph. My code seems like it should work but upon testing it does not, and I don't know what the problem is.

Edit: I think I figured it out!

👍︎ 4
💬︎
📅︎ Dec 14 2020
🚨︎ report
Visualizing A* and Dijkstra's pathfinding algorithm using pygame youtu.be/yVtGJ0uIeGc
👍︎ 15
📰︎ r/pygame
💬︎
📅︎ Oct 07 2020
🚨︎ report
Learn the Dijkstra algorithm step by step (easy to understand) youtube.com/watch?v=i3IRT…
👍︎ 2
📰︎ r/coding
💬︎
📅︎ Nov 24 2020
🚨︎ report
Dijkstra Algorithm Question: Which node do you visit if 2 options have the same distance?

Do you do both before moving on and the program splits?

Example: https://i.imgur.com/LJsUXSF.png

Starting with s, the smallest distance is to node 2. So you visit node 2 next. Next, the distance to node 1 and node 3 will be the same. So which do you visit?

I tried following just one path when there were 2 same options. However, this backed me into a corner on the graph and I got stuck on Node 3, with Node t being the only node left that was unvisited.

👍︎ 2
💬︎
📅︎ Oct 09 2020
🚨︎ report
Is there a way to implement Dijkstra's algorithm for a graph created based on user's input?

So I have to create this program that is supposed to find the shortest path between every pair of cities given a .txt file that the user inputs. The file contains the names of the cities in the first line (this would be the vertices), and the subsequent lines represent the distance between some of the cities (this would be the weighted edges). However, every single piece of code I've found for Dijkstra's algorithm either A. Is created based on an example (a graph that already exists, so they know how many edges there are, and their weights) or B. Ask the user to input the number of edges and the weights using matrices.

The thing with those implementations is that my program needs to work with whatever the user inputs, they could input 5 cities or they could input 100, so I don't know how many vertices and edges my graph is going to have. I was able to write code to generate a graph based on this conditions, but I can't seem to figure out how to implement Dijkstra's algorithm to that graph that I'm able to create. Any ideas of what I can do? Thanks in advance

👍︎ 2
💬︎
📅︎ Nov 10 2020
🚨︎ report
dijkstra's shortest path algorithm in java

Hey I am trying to use dijkstra's algorithm to find the shortest path between a source and destination. The implementation i am going off is https://www.geeksforgeeks.org/printing-paths-dijkstras-shortest-path-algorithm/ . The problem i have is that I want a path from source to destination (e.g. from source 0 to destination 6 (0->6)), however the given code gives a path to all vertices (e.g. 0->1,2,3,4,5,6...etc). I have tried removing `for (int i = 1; i &lt; nVertices; i++)` which i thought was the loop that does it for all the vertices, but I seemed to be wrong. Is there any way i can use this algorithm for just 1 source and 1 destination. Thank you.

``````class DijkstrasAlgorithm {

private static final int NO_PARENT = -1;

// Function that implements Dijkstra's
// single source shortest path
// algorithm for a graph represented
// representation
int startVertex)
{

// shortestDistances[i] will hold the
// shortest distance from src to i
int[] shortestDistances = new int[nVertices];

// added[i] will true if vertex i is
// included / in shortest path tree
// or shortest distance from src to
// i is finalized

// Initialize all distances as
// INFINITE and added[] as false
for (int vertexIndex = 0; vertexIndex &lt; nVertices;
vertexIndex++)
{
shortestDistances[vertexIndex] = Integer.MAX_VALUE;
}

// Distance of source vertex from
// itself is always 0
shortestDistances[startVertex] = 0;

// Parent array to store shortest
// path tree
int[] parents = new int[nVertices];

// The starting vertex does not
// have a parent
parents[startVertex] = NO_PARENT;

// Find shortest path for all
// vertices
``````
... keep reading on reddit ➡

👍︎ 3
💬︎
📅︎ Oct 25 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Very useful) youtu.be/-O-jQC6iHYE
👍︎ 17
💬︎
📅︎ Oct 18 2020
🚨︎ report
Maze Solver Visualizer - Dijkstra's algorithm (asynchronous neighbours) v.redd.it/xb71rqy5l5q41
👍︎ 2k
📰︎ r/Python
💬︎
📅︎ Apr 01 2020
🚨︎ report
Dijkstra's algorithm now running in linear time on a 90x90 grid v.redd.it/t7zvu5grgrr41
👍︎ 2k
📰︎ r/Python
💬︎
📅︎ Apr 09 2020
🚨︎ report
Comparing A* and Dijkstra's Path-finding algorithm Side by side. (With Code) youtu.be/yVtGJ0uIeGc
👍︎ 11
💬︎
📅︎ Oct 07 2020
🚨︎ report
Visualising Dijkstra vs DFS vs A* pathfinding algorithms v.redd.it/aysotawjgys41
👍︎ 695
📰︎ r/Python
💬︎
📅︎ Apr 15 2020
🚨︎ report
👍︎ 2
💬︎
📅︎ Oct 03 2020
🚨︎ report
What is the time complexity for dijkstra's algorithm using an adjacency matrix & priority queue?

I'm struggling to figure out what the time complexity would be

Iterating over the vertices costs V

Removing the min costs logV

Iterating through the vertex's edges costs V

Adding edges to queue costs logV (total costs of adding edges would be ElogV)

I think that's O(V^2+ElogV)? Since it has to iterate over the entire matrix and add the edges but I'm not sure. Also if I were to just have the while loop run until all vertices were removed from the queue, regardless if all shortest paths were found already or not, does that mean it would be O(EV+ElogV)?

👍︎ 2
💬︎
📅︎ Sep 10 2020
🚨︎ report
Dijkstra’s algorithm solving
1. Find the shortest path spanning tree for the weighted directed graph with vertices A, B, C, D, and E given using Dijkstra’s algorithm.

https://imgur.com/a/8vrzet9

👍︎ 14
💬︎
📅︎ Jun 03 2020
🚨︎ report
Updated Dijkstra's Algorithm with diagonals v.redd.it/nlustas7o3251
👍︎ 35
📰︎ r/pygame
💬︎
📅︎ May 31 2020
🚨︎ report
Dijkstra's Algorithm in Pygame v.redd.it/lwso9g7ijw151
👍︎ 31
📰︎ r/pygame
💬︎
📅︎ May 30 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Graph) youtu.be/iu3jGzCHwnE
👍︎ 1k
💬︎
📅︎ Nov 08 2019
🚨︎ report
Algorithm alternatives for when Dijkstra's fails?

Say I have a graph with distances as weights but each edge also has some random "failure factor" such as 0.23, 0.31, etc.. and if the sum of the failure factors adds up to 1, that route is deemed a failure and cannot be used. I have some code that runs Dijkstra's on a graph and finds the shortest path from A-B with no problem when considering distance weights, but that shortest path may actually be a failure when considering the failure factor and alternative routes will need to be considered.

What are some algorithms that quickly give the shortest path between A-B, and also some alternatives in case of failure? Should I even use dijkstra's at all initially or just swap it out for some other algorithm? Or should I run dijkstra's first, and if the shortest path fails, then call some other algorithm? Not too familiar with graph algorithms so anything helps!

👍︎ 5
💬︎
📅︎ Apr 13 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Graph) youtu.be/iu3jGzCHwnE
👍︎ 180
💬︎
📅︎ Jan 26 2020
🚨︎ report
Using network graph library to build an ui for dijkstra algorithm

I have implemented djktra algorithm in cli format but now i want to give it a ui,so i am thinking to use sigma js or viz js to implement the ui

my question is can i create node and edge then change the node color and edge width dynamically using this 2 library and if i can which one should i choose.

👍︎ 2
💬︎
📅︎ Jun 21 2020
🚨︎ report
[Updated] Maze Solver Visualizer - Dijkstra's algorithm v.redd.it/6cdfbi5r3lr41
👍︎ 20
📰︎ r/Python
💬︎
📅︎ Apr 08 2020
🚨︎ report
I have a working Dijkstra algorithm code for solving mazes but I am looking for more performance

This is my dijkstra's algorithm code... it solves any order square mazes...

``````from copy import deepcopy
from math import inf
import maze_builderV2 as mb

def dijkstra(maze, order, pos, finalpos):

mazemap = {}

def scan(): # Converts raw map/maze into a suitable datastructure.
for x in range(1, order+1):
for y in range(1, order+1):
mazemap[(x, y)] = {}
t = [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]
for z in t:
# print(z, z, maze[z][z])
if maze[z][z] == 'X':
pass
else:
mazemap[(x, y)][z] = 1

scan()

unvisited = deepcopy(mazemap)
distances = {}  # Stores shortest possible distance of each node
paths = {}  # Stores last node through which shortest path was acheived for each node

for node in unvisited:  # Initialisation of distance information for each node
if node == pos:
distances[node] = 0  # Starting location...
else:
distances[node] = inf

while unvisited != {}:
curnode = None
for node in unvisited:
if curnode == None:
curnode = node
elif distances[node] &lt; distances[curnode]:
curnode = node
else:
pass

# cannot use unvisited map is it will keep changing in the loop
for childnode, length in mazemap[curnode].items():
if length + distances[curnode] &lt; distances[childnode]:
distances[childnode] = distances[curnode] + length
paths[childnode] = curnode

unvisited.pop(curnode)

def shortestroute(paths, start, end):
shortestpath = []
try:
def rec(start, end):
if end == start:
shortestpath.append(end)
return shortestpath[::-1]
else:
shortestpath.append(end)
return rec(start, paths[end])
return rec(start, end)
except KeyError:
return False

finalpath = shortestroute(paths, pos, finalpos)

if finalpath:
for x in finalpath:
if x == pos or x == finalpos:
pass
else:
maze[x][x] = 'W'
else:
pass
``````

Problem is that

... keep reading on reddit ➡

👍︎ 6
💬︎
📅︎ Feb 10 2020
🚨︎ report
I cannot implement Dijkstra's algorithm in C++

I have tried to implement Dijkstra's algorithm( https://cp-algorithms.com/graph/dijkstra_sparse.html ) in C++, but I keep getting an error, and I don't know what it is.

Here is my code:

``````#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;utility&gt;
#include &lt;queue&gt;
using namespace std;
const int mint=1e5;
bool visited[mint+10]={false};
const long long  INF=1e18;
long long distanca[mint+10]={INF};
void dijkstra(vector&lt;vector&lt;pair&lt;int,int&gt; &gt; &gt; graf,int start)
{
visited[start]=true;
distanca[start]=0;
priority_queue&lt;pair&lt;long long,long long&gt;,vector&lt;pair&lt;long long,long long&gt; &gt;,greater&lt;pair&lt;long long,long long&gt; &gt; &gt; q;
q.push(make_pair(0,start));
while(!q.empty())
{
long long node=q.top().second;
visited[node]=true;
if(distanca[node]&lt;q.top().first)
{
q.pop();
continue;
}
q.pop();
for(int i=0;i&lt;graf[node].size();i++)
{
if(!visited[graf[node][i].first])
{
long long dist=distanca[node]+graf[node][i].second;
if(distanca[graf[node][i].first]&gt;dist)
{
distanca[graf[node][i].first]=dist;
q.push(make_pair(dist,graf[node][i].first));
}
}
}
}
}
int main()
{
int n,m;
cin&gt;&gt;n&gt;&gt;m;
vector&lt;vector&lt;pair&lt;int,int&gt; &gt; &gt; graf(n+1);
int inp1,inp2,inp3;
for(int i=0;i&lt;m;i++)
{
cin&gt;&gt;inp1&gt;&gt;inp2&gt;&gt;inp1;
graf[inp1].push_back(make_pair(inp2,inp3));
graf[inp2].push_back(make_pair(inp1,inp2));
}
dijkstra(graf,1);
cout&lt;&lt;distanca[n]&lt;&lt;endl;
}
``````

Can anybody find an error here? Thanks in advance.

👍︎ 7
💬︎
📅︎ Feb 29 2020
🚨︎ report
Help me implement Dijkstra's algorithm for a graph implemented adjacency lists

I'm currently trying to implement the shortest path algorithm, using a graph implemented through adjacency lists. If I understand correctly the idea of the algorithm, I should make the values of all elements in my array of adjacency lists equal some value representing infinity. In this toy example, I try to set the value of 9999 to the vertexes of the lists and fail for unknown to me reasons. It seems, that one of my elements loses a pointer to another, but I cannot understand why.

Even if I solved this problem, I still have one big issue: I don't understand how am I supposed to continue with the implementation of this algorithm afterwards. Am I supposed to replace the values of every vertex in the list with the value of the weight of the line connecting it to the head element of the list?

Consider: I have a list 0 |-> 1 -> 2, 1| -> 0 -> 3, 2| -> 0, 3| ->1. If I say these are my adjacency lists, how should I proceed? Should I replace the vertexes of my list with the value representing infinity, and then replace them with the sum of the weight and the value of the previous vertex? If so, can you help me understand how I shoud implement it, without mismanaging my pointers?

👍︎ 2
💬︎
📅︎ May 28 2020
🚨︎ report
What is the original version of Dijkstra Algorithm?

I see there are so many variations on this Algorithm. What really confuses me is that when going through the nodes, it keeps looking for the shortest edge first (just like using Min-Heap and pop out for the minimum edge connected node). But even if I finding nodes that are not connected by smallest distance edge, as long as I update when the adjacency nodes are smaller than how it was, it seems like it still works. I think this kind of looks like BFS but is this wrong? or is it less efficient when it comes to time complexity? I am just so confused about the original version of this algorithm and my method of solving this

👍︎ 2
💬︎
📅︎ Mar 06 2020
🚨︎ report
Trying to understand the complexity of the Dijkstra algorithm

Hello,

I am currently trying to understand the complexity of the Dijkstra algorithm. I understand the algorithm itself, however, am struggeling to comprehend how one can determine its complexity.
I know that it can reach different complexities, but am only looking into understanding the reasoning behind the complexity of O(|V|^2).

I am preferably looking for a detailed explanation.

Can anyone help? I am open to any kind of format- reddit comment, youtube videos, blogs, websites, etc.

👍︎ 2
💬︎
📅︎ Nov 30 2020
🚨︎ report
Algorithm alternatives for when Dijkstra's fails?

Say I have a graph with distances as weights but each edge also has some random "failure factor" such as 0.23, 0.31, etc.. and if the sum of the failure factors adds up to 1, that route is deemed a failure and cannot be used. I have some code that runs Dijkstra's on a graph and finds the shortest path from A-B with no problem when considering distance weights, but that shortest path may actually be a failure when considering the failure factor and alternative routes will need to be considered.

What are some algorithms that quickly give the shortest path between A-B, and also some alternatives in case of failure? Should I even use dijkstra's at all initially or just swap it out for some other algorithm? Or should I run dijkstra's first, and if the shortest path fails, then call some other algorithm? Not too familiar with graph algorithms so anything helps!

👍︎ 3
💬︎
📅︎ Apr 13 2020
🚨︎ report