graph-theory

prolog graph depth first search

梦想的初衷 提交于 2020-12-13 07:18:15
问题 I've seen other questions about depth first search but my problem is slightly different and I really don't get it. In prolog, I represent my undirected graph like this: [0-[1,5], 1-[0,2], 2-[1,3], 3-[2,0], 5-[0]] Which is a set of key-value, where the key represents the node and the list: -[] represents its neighbors. I don't know how to do a depth first search with this model. I've tried many solution. I want a really basic recursive algorithm like this one: dfs(v, visited): if visited[v]

prolog graph depth first search

为君一笑 提交于 2020-12-13 07:17:05
问题 I've seen other questions about depth first search but my problem is slightly different and I really don't get it. In prolog, I represent my undirected graph like this: [0-[1,5], 1-[0,2], 2-[1,3], 3-[2,0], 5-[0]] Which is a set of key-value, where the key represents the node and the list: -[] represents its neighbors. I don't know how to do a depth first search with this model. I've tried many solution. I want a really basic recursive algorithm like this one: dfs(v, visited): if visited[v]

prolog graph depth first search

旧街凉风 提交于 2020-12-13 07:16:54
问题 I've seen other questions about depth first search but my problem is slightly different and I really don't get it. In prolog, I represent my undirected graph like this: [0-[1,5], 1-[0,2], 2-[1,3], 3-[2,0], 5-[0]] Which is a set of key-value, where the key represents the node and the list: -[] represents its neighbors. I don't know how to do a depth first search with this model. I've tried many solution. I want a really basic recursive algorithm like this one: dfs(v, visited): if visited[v]

Big O in Adjency List - remove vertex and remove edge(time complexity cost of performing various operations on graphs)

左心房为你撑大大i 提交于 2020-12-05 09:28:44
问题 I have to prepare explanation of time complexity of removing vertex ( O(|V| + |E|) ) and edge ( O(|E|) ) in Adjency List. When removing vertex from graph with V vertices and E edges we need to go through all the edges ( O(|E|) ), of course, to check if which ones need to be removed with the vertex, but why do we need to check all vertices ? I don't understand why in order to remove edge we need to go through all the edges. I think I might have bad understanding from the beginning, so would

Networkx: Get the distance between nodes

故事扮演 提交于 2020-11-30 06:46:45
问题 I'm a beginner at using NetworkX and I'm trying to find a way to detect which nodes have distance x from each other. I've started by using this algorithm to get all pairs path=nx.all_pairs_dijkstra_path(G) But I'm still unsure on how to detect the distance between nodes using a for loop. I'd appreciate any help. Thank you 回答1: NetworkX has methods for automatically calculating the shortest paths (or just the path lengths) for weighted and unweighted graphs. Make sure that you use the correct

Algorithm for minimum vertex cover in Bipartite graph

天涯浪子 提交于 2020-08-08 09:20:41
问题 I am trying to figure out an algorithm for finding minimum vertex cover of a bipartite graph. I was thinking about a solution, that reduces the problem to maximum matching in bipartite graph. It's known that it can be found using max flow in networ created from the bip. graph. Max matching M should determine min. vertex cover C, but I can't cope with choosing the vertices to set C. Let's say bip. graph has parts X, Y and vertices that are endpoints of max matching edges are in set A, those

I'm trying to perform the transitive reduction of directed graph in Python

坚强是说给别人听的谎言 提交于 2020-07-18 06:31:11
问题 As a warning, I'm still a bit inexperienced in python I'm trying to perform the transitive reduction of directed graph using the networkx library. I've figured out an algorithm but I'm having trouble implementing it. After a quick search, I found algorithms similar to mine in other stack exchange questions but no demonstrations of how to actually code the algorithm. Here's my algorthm: For X in Nodes For Y in Nodes For z in Nodes if (x,y) != (y,z) and (x,y) != (x,z) if edges xy and yz are in

Job scheduling with minimization by parallel grouping

做~自己de王妃 提交于 2020-07-07 16:16:36
问题 I have a job scheduling problem with a twist- a minimization constraint. The task is- I have many jobs, each with various dependencies on other jobs, without cycles. These jobs have categories as well, and can be ran together in parallel for free if they belong to the same category. So, I want to order the jobs so that each job comes after its dependencies, but arranged in such a way that they are grouped by category (to run many in parallel) to minimize the number of serial jobs I run. That

Job scheduling with minimization by parallel grouping

人盡茶涼 提交于 2020-07-07 16:13:31
问题 I have a job scheduling problem with a twist- a minimization constraint. The task is- I have many jobs, each with various dependencies on other jobs, without cycles. These jobs have categories as well, and can be ran together in parallel for free if they belong to the same category. So, I want to order the jobs so that each job comes after its dependencies, but arranged in such a way that they are grouped by category (to run many in parallel) to minimize the number of serial jobs I run. That