If I have a directed graph with a cycle and only positive weights, and instead of using Priority Queue, I use a queue and keep adding all children, including those that were visited because I choose not to track the visited, can my algo fall in infinite loop? I am unable to develop the intuition for this and also not sure if my understanding is correct.
Dijkstra's algorithm for directed graph with positive weights and a cycle
288 views Asked by curiousengineer At
1
There are 1 answers
Related Questions in ALGORITHM
- MCNP 6 - Doubts about cells
- Given partially sorted array of type x<y => first apperance of x comes before first of y, sort in average O(n)
- What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- Dots and Boxes with apha-beta pruning
- What is the average and worst-case time complexity of my string searching algorithm?
- Building a School Schedule Generator
- TC problem 5-2:how to calculate the probability of the indicator random variable?
- LCA of a binary tree implemented in Python
- Identify the checksum algorithm
- Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Algorithm to find neighbours of point by distance with no repeats
- Asking code suggestions about data structure and algorithm
- Heap sort with multithreading
Related Questions in DATA-STRUCTURES
- Why is the runtime for this O(n)?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- What is the problem in my "sumAtBis" code?
- Asking code suggestions about data structure and algorithm
- What would be the most efficient way to store multiple sets of fixed arrays (std::vector)?
- About Suffix Trees features
- Getting wrong answer in Binary Search solution
- Are there techniques to mathematically compute the amount of searching in greedy graph searching?
- AVL tree Nth largest operation - How to have all my tests pass? JAVA
- Why does the map size change?
- Complexity in Union of disjointed sets with lists
- Hash collisions in Golang map resolving
- C++ ordered map optimized with index access
- How to sort this list of strings along with the strings and output the result as expected?
- Why deleting an element in a linkedlist costs O(1)
Related Questions in DIJKSTRA
- Are there any tools or NuGet packages available for C# (Windows Forms) that assist in visualizing Dijkstra's algorithm?
- shortest path algorithm with expected cost
- Shortest path finding in grid with turn cost
- Simplify 2D map to optimize pathfinding
- pgr_dijkstra returns "invalid memory alloc request size 1080000000" for large table
- Applying Dijkstra Algorithm To Find Lowest Energy Path
- undirected graph - Shortest path with Vertex and edges Weight
- Simplification of O((V + E) logV) time complexity
- Obtaining the resulting graph from ShortestPathsDijkstra
- Unabale to find the best case time complexity of priority queue Dijkstra Algorithm
- How to show the nodes with shortest distance from priority queue in dijkstra algorithm?
- How can I add one stop point to the distance between two cities in the Dijkstra algorithm?
- making a networkx network from geodataframe of a line- how2 make the network edges' weights correspond to the length of the line (in m) between nodes
- i have greedy and dijkstra algorithms with the same distance. My question is which distance to choose, B to C or B to D
- Performance of a variant of Dijkstra's algorithm
Related Questions in DIRECTED-ACYCLIC-GRAPHS
- I want to monitor a job triggered through emrserverlessstartjoboperator. If the job is either is success or failed, want to rerun the job in airflow
- airflow dags not running as expected
- Create a daily DAG that will run for multiple days
- Airflow config for running concurrent DAG tasks
- Algorithm for total flow through weighted directed acyclic graph
- Scalable Python Shortest Path on Large DAG with Multiple Walkers
- Finding path with smallest GCD of nodes's weights in directed graph
- How to Stop an Airflow DAG and Skip Future Processing if File is Empty?
- Is there a way to test looser airflow DAG dependencies? i.e. not direct dependencies
- Can multiprocessing in Python be used to simulate a graph evolving through time?
- Airflow Parallel DAG runs
- How perform task in airflow that executes regardless of failed tasks but fail the DAG when error appeared in previous tasks?
- Create custom Apache Airflow FileSensor that retries after sensor timeout
- Cost for using GoogleCloudStorageToBigQueryOperator in Airflow
- How can I successfully start the apache airflow db
Related Questions in CYCLIC-GRAPH
- minimum collection of vertice disjoint path that covers a given vertice set
- Difference between a directed cycle and a strongly connected component
- Dijkstra's algorithm for directed graph with positive weights and a cycle
- Finding longest path in a Directed Cyclic Graph
- Finding All Bounded-Length Simple Cycles in a Directed Graph
- Testing whether a path in a directed graph does not cause cycles
- Algorithm to resolve circular dependencies?
- Finding a cycle path in directed graph
- logic for method to detect cycle in an undirected graph
- With multiple cycles between 2 nodes
- Write a predicate that works for cyclic graph to check if there exists a path between two nodes using prolog
- Modification of code for printing cycles in the graph
- How to convert a directed graph to its most minimal form?
- Memoizing traversal over a cyclic graph
- Converting cyclic graph to acyclic in a weighted graph
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
For this consider the following graph:
and consider the pseudo code, whithout tracking the visited nodes.
We know we have a cycle and assume that the edges have weights larger than zero. By the algorithm, we know after at most 2 steps we are in the cycle starting with B. Scanning its neighbors, C, and updating its distance and adding its neigbors again. Doing this until the current node is E. By this point, we know that the distance from E is smaller than infinity and we have D and F in the queue. We again update the distance of F, add its neigbors(which is empty) and update the distance of D. If we again add the neigbors of D to the queue, we have B in the queue. In line 18 we can see that we are only adding nodes to the queue, if the distance of the previous node is smaller than the current distance of B. Since, we only have edge weights larger than 0, there is no possibility that the distance of D is smaller than distance of B. Hence, we are than not adding any further nodes to the queue, which will leave it empty. If the queue is empty, the algorithm will terminate. If we, e.g. would slightly modify the algorithm, s.t. we always its neighbors to the queue, yes there can be cases, in which the algorithm doesn´t terminate. But this only the case, if we don´t check if the distance is smaller or not keep track of the visited nodes.
Long story short:
If you have something to keep track of the current state of the procedure, let it be the distance of the node or which node was visited etc., you won´t run into any endless loop. Unless the edges weights are negative.