Questions tagged [longest-path]

106 questions
0
votes
1 answer

Trying to find the longest induced path using DFS in a graph

here is the code I am currently applying that is a DFS algorithm in order to find the longest induced path (the longest 'snake') of a graph: def dfs(node, adj, dp, vis): # Mark as visited vis[node] = True #print(vis[adj[node][0]]) #…
0
votes
1 answer

how to find shortest path and longest path in an undirected graph?

I have a general question regarding how to find shortest path and longest path in an undirected graph with simple edges where edges have no weights. Is it a correct conclusion that we need to use DFS algorithm to find the longest path in a graph,…
0
votes
1 answer

Efficient way to keep only longest paths in a DAG?

Is there an efficient way to remove all edges that are not part of a longest paths between two nodes in a DAG? For example, for the graph (DAG): (1->2, 2->3, 2->4, 1->3, 1->4) I want to remove the edges 1->3, 1->4 since the paths 1->2->3, 1->2->4…
0
votes
0 answers

Longest path in a tree using dynamic programming

I recently solved a problem of the longest path by using BFS twice. I also learned that dynamic programming can be used to solve the longest path in a directed acyclic graph. What would the pseudocode and recursion equation/runtime be for finding…
0
votes
1 answer

get longest path between two nodes with common nodes

I have a graph in which the connection of the friends and the cities where they live are shown. The connection of the friends is specified by means of black arrows and that of the cities is specified with dotted lines. I want to get the longest path…
0
votes
1 answer

Return the list of items which are part of the longest path from Tree's root to a Leaf in a General Tree

Given this Class that represents a tree , i got a little confused on how would i return a list that will consist of nodes that are part of the tree's height . public class TreeNode { private T m_Data; public T Data { …
0
votes
0 answers

Longest 'Random Non intersecting' path in a grid

Given a grid size(m*n), how could one generate a random path between a start(x1, y1) and end(x2, y2) point with the added condition that the random path covers all the nodes e.g. Grid of size 5*6 Start Point -> (1, 1) End Point -> (1, 6) What…
future.open
  • 25
  • 1
  • 5
0
votes
0 answers

Is there any faster way to find the path with maximum attribute [duration] of vertices in a directed acyclic graph?

this code works in small networks (30 vertices) but for a 300 vertices network takes hours! Is there a faster way? to calculate-duration ask act 0 [set color green] set pathlist [ ] loop [ if all? deps [color = green] [stop] let path [0] …
0
votes
0 answers

Finding longest root to leaf path in a tree

I need to find the longest ROOT to LEAF path in a tree. I already have code to find the shortest root to leaf and I was wondering if I could reuse it in any way to find the longest path. // Recursive function used by leftMostShortest // to print…
0
votes
2 answers

How to allow negative weights on a Graph in JGraphT?

I have a graph and want to find the LONGEST path from source to sink. My idea was to reverse the weight to negative numbers and run dijkstra on it, as implemented in JGraphT ListenableDirectedWeightedGraph g = new…
Flontis
  • 307
  • 1
  • 4
  • 13
0
votes
1 answer

Extract longest common path between two lists in python

Lets say there are two lists L1=[['A', ['C', ['B', ['D', 0]]]], [['A', ['D', ['K', ['C', ['E', 0]]]]], [['A', ['C', ['B', ['M', 0]]]]] and L2=[['A', ['C', ['B', ['K', 0]]]], [['A', ['C', ['B', ['B', ['E', 0]]]]], [['A', ['D', ['K',…
0
votes
0 answers

Longest acyclic path from A to B in a graph

I'm learning C language. And I want to find the longest acyclic path in a graph from A to B. For example, I have a graph like this: 0 | 1 / \ 2 --- 3 | / \ …
user8400129
  • 193
  • 1
  • 7
0
votes
0 answers

How can I calculate the complexity of my longest path problem?

I need to find the longest path in which the values of the points are getting bigger. First I find the number of steps of the longest path, and then I use DFS to search all the point in my map and see if they offer a solutions with that number of…
0
votes
1 answer

How to implement simulated annealing to find longest path in graph

I've found a piece of pseudocode which explains simulated annealing for longest path problem, but there are a few details which I do not understand. Currently I have implemented a structure representing graph, and method to generate random graph and…
Zarrie
  • 325
  • 2
  • 16
0
votes
1 answer

Recursive function to find all paths to a specific target

I need to find the longest path to a given target. The data is a dictionary of ids with the value being a list of all ids that point to that id. Also worth noting that each Id can only point to one other id. I tried to write a recursive function…