Questions tagged [longest-path]

106 questions
1
vote
2 answers

Python: Finding the longest path

I have a simple graph created as such in the below class Job(): def __init__(self, name, weight): self.name = name self.weight = weight self.depends = [] def add_dependent(self, dependent): …
ealeon
  • 12,074
  • 24
  • 92
  • 173
1
vote
1 answer

Algorithm for long path in particular square grid subgraph

Take the square tiling of the plane, and imagine a finite, connected and simply connected subset D of tiles. D can of course also be interpreted as a particular subgraph of the square grid by taking a node for each tile and connecting adjacent…
1
vote
1 answer

Maximum number of elements in the path of a matrix

I tried to solve a problem of map (matrix 4x4) using python. I want to find Maximum number of elements in the path of a map provided the next node must be lesser than the previous node with all possible combinations of elements in the matrix. 4 8 7…
Ramesh R
  • 13
  • 4
1
vote
1 answer

Find Longest Weighted Path from DAG with Networkx in Python?

I need a algorithm for find the longest weighted path in a directed, acyclic graph networkx.MultiDiGraph(). My graph has weighted edges and many edges have a null value as the weighting. In networkx doc I have found nothing for solve this problem.…
Robi Roboter
  • 43
  • 1
  • 7
1
vote
1 answer

Branch and bound strategy for longest path implementation

I am working on a problem which i have to solve with a branch and bound algorithm. Let's say we have n gas stations with different distance values from the starting point. Stations have different profits. We want to maximize the profit but each…
1
vote
4 answers

Find the length of longest chain formed using given words in String

Okk As programmer we love get involved in logic building but that is not the case some time we become blank over some type of puzzle as below mentioned. Let me declare that this is not any kind of homework or job stuff it simply a logic and…
Bhargav Modi
  • 2,605
  • 3
  • 29
  • 49
1
vote
1 answer

Fundamental differences between Widest Path and Longest Path problems

What are the differences between the widest path and longest path questions? More specifically, why can the former be solved by finding the maximum spanning tree whereas the latter cannot. I know in drawing out the maximum spanning tree it's…
1
vote
0 answers

Find Longest Path on DAG with Networkx in Python

I have a very large DAG of strings (~200k). I would like to find the longest path that exists in this graph. The below code is how I've set up the graph (from the list of strings new_list). #create new empty graph g = nx.DiGraph() #add all words to…
1
vote
0 answers

Does this class of MDP have an efficient solution?

I've been working on making a game solver for about a month now, trying a variety of strategies but most have been oriented around brute force. This works for simpler cases of the game but it fails for more complex cases (higher game tree depth).…
1
vote
1 answer

Longest path in a Direct Acyclic Graph

How can I find the longest path in a DAG with no weights? I know that the longest path from A to B can be found in linear time if the DAG is topologically sorted, but I need to find the longest path in all the graph. Is there any way faster than…
1
vote
1 answer

Find longest path between set of nodes in a tree

Recently came across a programming question. Given a tree, can be non-binary, can be a single chain (or linear), with N nodes. Input will be a set of K nodes, denoted a1,a2....ak. I'd like to find the longest simple path(s) that start from one of…
user2129227
  • 97
  • 1
  • 4
1
vote
1 answer

Longest Path Algorithm for Layer Assignment

I'm working on a program to generate an organizational chart of a company. I have been reading about the longest path algorithm to layer the vertices, and one thing has been bugging me. The reading that I have done suggests that the graph should be…
Eric
  • 688
  • 2
  • 9
  • 23
1
vote
1 answer

How to find the longest path in an acyclic directed graph using OGDF library?

I'm new to OGDF library and need to find the longest path in an acyclic directed graph (I want to use OGDF built in functions). I know, it is possible to find longest path using shortest path algorithms with negative weights for edges, but also…
Hamed
  • 202
  • 1
  • 4
  • 10
0
votes
0 answers

How to get the longest path in Python for an undirected graph, limited by specified weight?

My objective is to determine a way to find the longest path in a given graph, limited by the maximum total weight of the visited edges. Edges cannot be visited twice. import networkx as nx G = nx.Graph() G.add_edge(0,1, weight=10) G.add_edge(0,2,…
Pythoner
  • 460
  • 6
  • 23
0
votes
1 answer

Python code for longest common subdirectory in given path list

I have been given a list of folder structures like path = [ "/home/User/Desktop/gfg/test", "/home/User/Desktop/gfg/file", "/home/User/Desktop/geeks/folders" , "/home/User/Desktop/../geeks/a/folders"] and we have to find out the common subdirectory…