1,954 questions
-2
votes
0
answers
79
views
How'd you make algorithm that'll find shortest way to sort sequence of numbers just by applying function f(x) that will make x to closest lower prime? [closed]
Imagine you get sequence of integers:
[a1 a2 a3 ... an]
where:
1 <= a <= 10^6
1 <= n <= 10^6
You are given a function f(x) that can change a number to the closest lower prime number, or ...
1
vote
2
answers
596
views
Optimal substructure of shortest path and Dijkstra
I have very well understood Optimal substructure property of shortest path. Which says that-
A shortest path from x to y via z contains a shortest path from x to
z.
Now I want to understand how ...
4
votes
0
answers
1k
views
What is an atomic heap?
I am trying to understand Thorup's latest priority Queue which has delete_min operation O(log log N) as presented in his paper.
He refers to Fredman and Williard's Atomic Heap as a part of his ...
-3
votes
1
answer
122
views
PriorityQueue Comparator weird behavior when sort order is fetched from hashmap
While working in LeetCode 675, I came across a weird behavior with PriorityQueue Comparator that I can't explain.
For brevity, I'll state the gist of the problem statement; interested parties can read ...
5
votes
1
answer
80
views
Can bi-directional breadth-first search be used to enumerate ALL shortest paths between two specific nodes in an unweighted directed (acyclic?) graph?
It is alleged that the standard BFS can be extended to output all possible shortest paths between two given vertices in a directed unweighted graph (without loops? it does not seem to matter whether ...
14
votes
3
answers
28k
views
How to find all shortest paths
I have a graph and I want to find all shortest paths between two nodes. I've found a shortest path between two nodes by BFS. However, it just gives me one of the shortest paths if there exists one ...
133
votes
10
answers
121k
views
Negative weights using Dijkstra's Algorithm
I am trying to understand why Dijkstra's algorithm will not work with negative weights. Reading an example on Shortest Paths, I am trying to figure out the following scenario:
2
A-------B
\ /...
1
vote
2
answers
808
views
In Dijkstra's algorithm why must it first expand nodes with the current least cost?
I have read in other posts that Dijkstra's algorithm always expands the shortest path first. Why must it be implemented in such a way? Say we created a relaxed version of Dijkstra's that expands any ...
1
vote
1
answer
176
views
Finding shortest path for grid with rotating cells
I stumbled upon a problem like this:
Let's say you have some number of grids. Each grid have the same dimension of rows and columns. Each cell in grid can be represented as either L or _ . Also take ...
1
vote
1
answer
54
views
Distance Discrepancy Between Latvia and Poland Round Trip Using Python’s scgraph Package
I came across a strange behavior, which I do not understand and might also be a bug. By coincidence, I found out that the distance in the rail network between Latvia and Poland is significantly higher ...
1
vote
2
answers
179
views
Error: recursive reference to query "shortestflight" must not appear within a subquery
From "Montreal" as the origin point, I'm trying to find the shortest path to go to another city. But I'm having difficulty when a city is looped.
demo at db<>fiddle
create table ...
11
votes
2
answers
16k
views
Eppstein's algorithm and Yen's algorithm for k shortest paths
I'm trying to understand exactly how these algorithms work, but I have been unable to find a simple explanation. I would greatly appreciate it if someone could provide me with a description of these ...
3
votes
3
answers
176
views
Shortest path in a Graph by reducing the Weight of multiple edges by half
Given a directed graph with positive edge weights, a source vertex, a destination vertex, and a integer M (M < 10), find the shortest path from the source to the destination. The twist is that M ...
0
votes
1
answer
53
views
Efficiently converting edgelist to distance matrix in Python
R user learning Python here. I have an undirected unweighted edgelist and I want a distance matrix, showing the shortest path between all my nodes. There are about 30000 nodes and 40000 edges, and my ...
0
votes
1
answer
137
views
how to find a path from source to target with necessary points constraint by A star algorithm
Using A star algorithm, it is easy to calculate the shortest path from the source point to target point. What if we add the constraint of necessary points? How to solve it ?
necessary points is a set ...
0
votes
1
answer
195
views
Priority queue implementation with the Dijkstra
The question asks about the maximum number of elements that can be present in the priority queue at any given time during the execution of Dijkstra's algorithm on the given graph.
I coudn't understand ...
0
votes
2
answers
126
views
How to find the shortest path not containing a pattern?
I am using Neo4j 5.9.0 community
Problem description :
My graph only has one type of relationship [:Relationship], and one type of node (:Node).
I want to find the shortest path between two nodes, but ...
1
vote
1
answer
165
views
Single Source - Single Destination Shortest Path (DFS + DP) - Time complexity?
Context:
I want to write an algorithm for finding the shortest(least cost) path from a fixed source to a fixed destination node in a weighted directed graph with non negative weights (can have cycles)....
1
vote
1
answer
842
views
Given a set of edges and an undirected graph, how do I pick the best edge to add to graph to minimize the shortest path?
What I'm thinking is, for each edge in the set of edges I can pick from, build a copy of the graph with that edge inserted into it, then run Dijkstra’s. The best edge will be from the graph with the ...
0
votes
1
answer
307
views
Bellman-Ford with Adjacency List (Shortest-path with negative weights)
I'm implementing my own version of the Bellman-Ford algorithm to find shortest paths with negative weights. However I'm not sure if this is correct, since in my opinion the complexity in my solution ...
4
votes
4
answers
5k
views
Find all shortest paths between all pairs of nodes in NetworkX
I am trying to get all shortest paths between all pairs of nodes in an undirected unweighted graph. I am currently using nx.all_pairs_shortest_path(), but I don't understand why it only returns one ...
2
votes
1
answer
482
views
Simplify 2D map to optimize pathfinding
I'm working on a personal project that requires solving the well-known shortest-path problem.
I have 256x256 tiles maps like the following:
Example map
I'm only interested in white (walkable) areas. ...
0
votes
1
answer
96
views
Identifying negative cycles in Bellman-Ford Algorithm
As I opted for option 1 and 3 (-6, infinity),(-7, Infinity) and applied the Bellman-Ford algorithm for shortest path calculation, the calculation did not show any negative cycles after n’th steps for ...
0
votes
3
answers
171
views
How to reconstruct the shortest path with BFS (Javascript) for Knight chess piece?
I'm currently working for a project with TOP and I'm asked to find the shortest path between 2 squares with a Knight on a 8x8 chessboard. Imagine I want to go from 0,0 to 7,7, my algo need to return ...
0
votes
0
answers
44
views
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?
I was given a problem that in a connected, weighted graph G = (N, A), find a connected subgraph G_s = (N_s, A_s), where |N_s| <= l and A_s = {(i, j): i \in N_s, j \in N_s, (i, j) \in A}, such that ...