This reminds me of "Dijkstra's Algorithm" from Further Maths πŸ˜‚
πŸ‘︎ 22
πŸ“°︎ r/6thForm
πŸ’¬︎
πŸ‘€︎ u/Mr-Appleeye
πŸ“…︎ 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
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ‘€︎ u/Fravona2211
πŸ“…︎ Nov 30 2020
🚨︎ report
What is Dijkstra's Algorithm? seedbx.com/understanding-…
πŸ‘︎ 14
πŸ“°︎ r/leetcode
πŸ’¬︎
πŸ‘€︎ u/aayusss21
πŸ“…︎ Dec 22 2020
🚨︎ report
I wish Chris Jordan would have studied Dijkstra's algorithm
πŸ‘︎ 121
πŸ“°︎ r/CricketShitpost
πŸ’¬︎
πŸ‘€︎ u/BiriyaniMonster
πŸ“…︎ Oct 19 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm youtu.be/-O-jQC6iHYE
πŸ‘︎ 230
πŸ“°︎ r/coding
πŸ’¬︎
πŸ‘€︎ u/GhOsT1679
πŸ“…︎ 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
πŸ“°︎ r/visualbasic
πŸ’¬︎
πŸ‘€︎ 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
πŸ“°︎ r/javahelp
πŸ’¬︎
πŸ‘€︎ u/jengawal
πŸ“…︎ Dec 14 2020
🚨︎ report
Visualizing A* and Dijkstra's pathfinding algorithm using pygame youtu.be/yVtGJ0uIeGc
πŸ‘︎ 15
πŸ“°︎ r/pygame
πŸ’¬︎
πŸ‘€︎ u/xX__NaN__Xx
πŸ“…︎ Oct 07 2020
🚨︎ report
Learn the Dijkstra algorithm step by step (easy to understand) youtube.com/watch?v=i3IRT…
πŸ‘︎ 2
πŸ“°︎ r/coding
πŸ’¬︎
πŸ‘€︎ u/finaldie
πŸ“…︎ 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
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/RayzTheRoof
πŸ“…︎ 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
πŸ“°︎ r/javahelp
πŸ’¬︎
πŸ‘€︎ u/Undesirable_11
πŸ“…︎ 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 < 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  
    // using adjacency matrix 
    // representation 
    private static void dijkstra(int[][] adjacencyMatrix, 
                                        int startVertex) 
    { 
        int nVertices = adjacencyMatrix[0].length; 
  
        // 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 
        boolean[] added = new boolean[nVertices]; 
  
        // Initialize all distances as  
        // INFINITE and added[] as false 
        for (int vertexIndex = 0; vertexIndex < nVertices;  
                                            vertexIndex++) 
        { 
            shortestDistances[vertexIndex] = Integer.MAX_VALUE; 
            added[vertexIndex] = false; 
        } 
          
        // 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
πŸ“°︎ r/javahelp
πŸ’¬︎
πŸ‘€︎ u/sdbs2243
πŸ“…︎ Oct 25 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Very useful) youtu.be/-O-jQC6iHYE
πŸ‘︎ 17
πŸ“°︎ r/leetcode
πŸ’¬︎
πŸ‘€︎ u/GhOsT1679
πŸ“…︎ Oct 18 2020
🚨︎ report
Maze Solver Visualizer - Dijkstra's algorithm (asynchronous neighbours) v.redd.it/xb71rqy5l5q41
πŸ‘︎ 2k
πŸ“°︎ r/Python
πŸ’¬︎
πŸ‘€︎ u/mutatedllama
πŸ“…︎ Apr 01 2020
🚨︎ report
Dijkstra's algorithm now running in linear time on a 90x90 grid v.redd.it/t7zvu5grgrr41
πŸ‘︎ 2k
πŸ“°︎ r/Python
πŸ’¬︎
πŸ‘€︎ u/mutatedllama
πŸ“…︎ Apr 09 2020
🚨︎ report
Comparing A* and Dijkstra's Path-finding algorithm Side by side. (With Code) youtu.be/yVtGJ0uIeGc
πŸ‘︎ 11
πŸ“°︎ r/madeinpython
πŸ’¬︎
πŸ‘€︎ u/xX__NaN__Xx
πŸ“…︎ Oct 07 2020
🚨︎ report
Visualising Dijkstra vs DFS vs A* pathfinding algorithms v.redd.it/aysotawjgys41
πŸ‘︎ 695
πŸ“°︎ r/Python
πŸ’¬︎
πŸ‘€︎ u/mutatedllama
πŸ“…︎ Apr 15 2020
🚨︎ report
πŸ‘︎ 2
πŸ“°︎ r/datastructures
πŸ’¬︎
πŸ‘€︎ u/AnimatedStudy
πŸ“…︎ 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
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ‘€︎ u/Correct_Ad9704
πŸ“…︎ 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
πŸ’¬︎
πŸ‘€︎ u/RadiantSkiesJoy
πŸ“…︎ Jun 03 2020
🚨︎ report
Updated Dijkstra's Algorithm with diagonals v.redd.it/nlustas7o3251
πŸ‘︎ 35
πŸ“°︎ r/pygame
πŸ’¬︎
πŸ‘€︎ u/Iceninja1234567
πŸ“…︎ May 31 2020
🚨︎ report
Dijkstra's Algorithm in Pygame v.redd.it/lwso9g7ijw151
πŸ‘︎ 31
πŸ“°︎ r/pygame
πŸ’¬︎
πŸ‘€︎ u/Iceninja1234567
πŸ“…︎ May 30 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Graph) youtu.be/iu3jGzCHwnE
πŸ‘︎ 1k
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/EddyTheDad
πŸ“…︎ 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
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ‘€︎ u/plsnoHIV
πŸ“…︎ Apr 13 2020
🚨︎ report
Dijkstra's Shortest Path Algorithm (Graph) youtu.be/iu3jGzCHwnE
πŸ‘︎ 180
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/lukescriptwalker
πŸ“…︎ 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.

Thanks in advance

πŸ‘︎ 2
πŸ“°︎ r/reactjs
πŸ’¬︎
πŸ‘€︎ u/mirsahib
πŸ“…︎ Jun 21 2020
🚨︎ report
[Updated] Maze Solver Visualizer - Dijkstra's algorithm v.redd.it/6cdfbi5r3lr41
πŸ‘︎ 20
πŸ“°︎ r/Python
πŸ’¬︎
πŸ‘€︎ u/mutatedllama
πŸ“…︎ 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[0], z[1], maze[z[0]][z[1]])
                if maze[z[0]][z[1]] == '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] < 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] < 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[0]][x[1]] = 'W'
else:
    pass

Problem is that

... keep reading on reddit ➑

πŸ‘︎ 6
πŸ“°︎ r/codereview
πŸ’¬︎
πŸ‘€︎ u/prithvidiamond1
πŸ“…︎ 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 <iostream>
#include <vector>
#include <utility>
#include <queue>
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<vector<pair<int,int> > > graf,int start)
{
    visited[start]=true;
    distanca[start]=0;
    priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > q;
    q.push(make_pair(0,start));
    while(!q.empty())
    {
        long long node=q.top().second;
        visited[node]=true;
        if(distanca[node]<q.top().first)
        {
            q.pop();
            continue;
        }
        q.pop();
        for(int i=0;i<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]>dist)
                {
                    distanca[graf[node][i].first]=dist;
                    q.push(make_pair(dist,graf[node][i].first));
                }
            }
        }
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<pair<int,int> > > graf(n+1);
    int inp1,inp2,inp3;
    for(int i=0;i<m;i++)
    {
        cin>>inp1>>inp2>>inp1;
        graf[inp1].push_back(make_pair(inp2,inp3));
        graf[inp2].push_back(make_pair(inp1,inp2));
    }
    dijkstra(graf,1);
    cout<<distanca[n]<<endl;
}

Can anybody find an error here? Thanks in advance.

πŸ‘︎ 7
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/balkanredditor005
πŸ“…︎ 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?

Code : https://pastebin.com/a3Uz5mub

πŸ‘︎ 2
πŸ“°︎ r/C_Programming
πŸ’¬︎
πŸ‘€︎ u/Merchander
πŸ“…︎ 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
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/poream3387
πŸ“…︎ 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
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/Fravona2211
πŸ“…︎ 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
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/plsnoHIV
πŸ“…︎ Apr 13 2020
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.