Questions tagged [longest-path]
106 questions
3
votes
2 answers
Split a tree into equal parts by deleting an edge
I am looking for an algorithm to split a tree with N nodes (where the maximum degree of each node is 3) by removing one edge from it, so that the two trees that come as the result have as close as possible to N/2. How do I find the edge that is "the…

Michal Ferko
- 95
- 1
- 9
3
votes
2 answers
Function to find the highest score path in a graph with python
I'm trying to make a function to find the highest score in a directed graph. I do have a start node and can't go throught the same node twice. I've tried to use recursive to get the sum of values until I hit one end node. Then I would call back my…

Artotim
- 85
- 5
3
votes
2 answers
Finding the hamiltonian path in a directed cyclic graph
i want to know if there is an algorithm to find the longest cyclic path in a directed weighted graph (i think this i a problem of finding the largest Hamiltonian sub-graph).
I need to start from one vertex and return to the same vertex, whit the…

Joksim
- 59
- 6
3
votes
2 answers
Longest path in directed acyclic graph in jgrapht library
I want to find the longest path in directed (acyclic) graph. Let's say that I know starting node - sink. The path should begin from this point.
I was thinking that I can set weights of edges to -1. There is many methods of finding all shortest path…

peter robens
- 31
- 3
3
votes
1 answer
Graph longest path using linear programming
I have a weighted directed graph where there are no cycles, and I wish to define the constraints so that I can solve a maximization of the weights of a path with linear programming. However, I can't wrap my head around how to do that.
For this I…

sharp_c-tudent
- 463
- 5
- 17
3
votes
1 answer
Longest path of weighted DAG using R igraph
I have implemented longest path calculation of a weighted DAG using R igraph.
My implementation (shown below) is slow for large graphs.
I would greatly appreciate any hints to speed it up.
Any thoughts on how far my implementation is from the best…

nandu
- 2,563
- 2
- 16
- 14
3
votes
2 answers
Longest Path in a grid
Given a grid G.
Each cell can contain numbers [0 - 9] inclusive or an upper case alphabetical letter (say Z);
we can start with the upper left corner.
Then if the cell number we are on is a, we can allowed to move exactly a cells up, down left or…

Hussein Hammoud
- 171
- 1
- 13
2
votes
1 answer
Is finding the largest cycle on a directed graph with 133 Nodes and 737 Edges Computable?
Trying to solve the longest cycle problem for a directed, unweighted graph with 133 nodes and 737 edges. (See also Wikipedia Longest Path Problem).
I tried using the networkx library for Python, but it wasn't able to compute it. Is it worth finding…

Fedaykin1200
- 23
- 4
2
votes
0 answers
Get all Paths between 2 Nodes in a simple graph using JGraphT
I' m currently studying the JGraphT libraries to manipulate Graphs in Java, in particular I'm trying to identify the longest path between 2 nodes in a simple graph and I know that I can get there by using a recursive method.
Anyway, I found in Java…

lfmvit
- 21
- 1
2
votes
1 answer
Why can't Bellman-Ford be used for Single Source Longest Path?
Dijkstra's cannot be used for longest path because it uses the property that the current shortest path will be for sure shorter than one of the other paths. This is correct, of course, assuming there are no negative edge weights. This concept is…

timg
- 381
- 2
- 13
2
votes
6 answers
Dijkstra's algorithm to find most weighted path
I just want to make sure this would work. Could you find the greatest path using Dijkstra's algorithm? Would you have to initialize the distance to something like -1 first and then change the relax subroutine to check if it's greater?
This is for a…

Matt
- 7,049
- 7
- 50
- 77
2
votes
1 answer
Longest path in unweighted undirected graph starting and finishing in the same vertex
I have a problem in which I need to find the longest path. Given an unveighted undirected graph. Starting from a given vertex I need to visit as many vertices as possible and finish in the same one without visiting each of them more then once.
Most…

Diaz
- 25
- 4
2
votes
3 answers
NetworkX: Find longest path in DAG returning all ties for max
I'm having trouble figuring out how to update the networkx dag_find_longest_path() algorithm to return "N" for ties instead of returning the first max edge found, or returning a list of all edges that are tied for max weight.
I first created a DAG…

SummerEla
- 1,902
- 3
- 26
- 43
2
votes
2 answers
Is longest possibly non-simple path in NP?
I know that the following problem is in NP-HARD: Given a simple graph G=(V,E), two vertices v, v' in V, an integer B, and a non-negative length function len: E-> Z+, is there a simple path from v to v' with length less than B?
My question is: Given…

Pafnuty
- 29
- 2
2
votes
1 answer
Longest route in 2D array from max to min
There is 2D array long[50][50] which is filled with random numbers from 0 to 100. I need to find the longest way from the biggest (or first highest) to the smallest. You can move up, down, left and right.
I found how to find single way: find the…

Peter Parker
- 560
- 1
- 5
- 17