depth-first-search

How can we find the initial node in order to apply the algorithm?

穿精又带淫゛_ 提交于 2019-12-13 08:59:53
问题 Consider the following graph G and consider that at an execution of the algorithm DFS at G, the edges of the graph are characterized as tree edges(t), back edges(b) , forward edges(f) and cross edges(c) as at the following graph. For each node of the graph find the discovery time and the finishing time of the node. In other words, for each node v of the graph, find the values d[v] and f[v] that associates the algorithm DFS with this node. Notice that there is only one possible assignment of

find minimum spanning tree using depth first search in C

对着背影说爱祢 提交于 2019-12-13 08:22:42
问题 I'm trying to implement an algorithm in c which finds MST using DFS. I've already found the DFS algortihm and i understand it pretty well. I also know that i should follow these steps to achieve my purpose : 1 Run DFS till you find an edge going backwards or DFS stopped. If stopped return G. 2 On the circle that is constructed by the backwards going edge find the heaviest edge and remove it from G. 3 Return to 1. Here is the DFS code : #include<stdio.h> void DFS(int); int G[10][10],visited[10

recursive implementation of Depth first search to find path from source to destination in Java

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 06:13:10
问题 I have this working code for finding path between source to destination non-recursively. I would like to implement recursively, but I am having difficulty in how to do it. This is my code for non-recursive implementation public boolean depthFirstSearch(String name1, String name2){ Vertex source = vertexMap.get(name1); Vertex dest = vertexMap.get(name2); clearAll(); Stack<Vertex> stack = new Stack<Vertex>(); source.setVisited(true); stack.push(source); while(!stack.isEmpty()){ source = stack

Will SCC pattern change if we reverse a graph(using Kosaraju's Algorithm)?

孤人 提交于 2019-12-13 02:56:53
问题 Assume we have a digraph, it is not a complete graph and has more than one SCC. I wonder if the patterns of Strongly Connected Component changes if we transpose the graph and use Kosaraju's Algorithm? By saying "transpose the graph" I mean flip the direction of edges. If we try to find SCC in the transposed/reversed graph instead of the original, will the SCC we find be different? I came up with this question as I misunderstood the algorithm of SCC and runs it on my transposed/reversed graph.

Java - Depth first search

这一生的挚爱 提交于 2019-12-13 02:24:48
问题 I have implemented two algorithms in Java and when testing depth first search it seems to be taking an incredible amount of time when there are 12 nodes, when using A* it completes it in seconds, I was just wondering if this is to be expected or am I doing something wrong? Its running the search in the background now as I type this and has been going for a few minutes. I wouldnt normally mind but ive got to test up to 500 nodes which could take days at this rate, is this something I should

Boost DFS how to save visited vertices?

蓝咒 提交于 2019-12-12 19:19:02
问题 I'm looking at the solution here, which doesn't work for me (but read under the === line to actually see the current problem). I tried: boost::undirected_dfs(G, vertex(0,G), boost::visitor(vis)); but I get error C2780: 'void boost::undirected_dfs(const Graph &,const boost::bgl_named_params<P,T,R> &)' : expects 2 arguments - 3 provided error C2780: 'void boost::undirected_dfs(const Graph &,DFSVisitor,VertexColorMap,EdgeColorMap)' : expects 4 arguments - 3 provided etc. I sort of get what the

Create Spanning Tree With DFS

天涯浪子 提交于 2019-12-12 17:05:21
问题 Running the Depth First Search (DFS) algorithm over a given graph G = (V,E) which is connected and undirected provides a spanning tree. While running DFS on the graph, when we arrive to a vertex which it's degree is greater than 1 , i.e - there is more than one edge connected to it , we randomly choose an edge to continue with. I'd like to know if the option to choose an edge (or a vertex) to continue with actually allows as to create every spanning tree of a given graph using DFS? 回答1: Since

error in the code given in skiena's book for the application of dfs to find a cycle in a graph

你说的曾经没有我的故事 提交于 2019-12-12 15:12:16
问题 This is the code for dfs. bool processed[MAXV+1]; /* which vertices have been processed */ bool discovered[MAXV+1]; /* which vertices have been found */ int parent[MAXV+1]; /* discovery relation */ #define MAXV 1000 /* maximum number of vertices */ typedef struct { int y; /* adjacency info */ int weight; /* edge weight, if any */ struct edgenode *next; /* next edge in list */ } edgenode; typedef struct { edgenode *edges[MAXV+1]; /* adjacency info */ int degree[MAXV+1]; /* outdegree of each

Which Procedure we can use for Maze exploration BFS or DFS

孤者浪人 提交于 2019-12-12 08:55:56
问题 I know we can use DFS for maze exploration. But I think we can also use BFS for maze exploration. I'm little bit confused here because most of the books and articles that I've read had used DFS for this problem. What I think is that the Best Case time complexity of DFS will be better as compared to BFS. But Average and Worst Case time complexity will be same for both BFS & DFS and thats why we prefer DFS over BFS. Am I right or I'm having some misconception 回答1: They have similar running time

Eliminating vertices from a graph [closed]

跟風遠走 提交于 2019-12-12 02:55:02
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . From Skiena's Book, Design a linear-time algorithm to eliminate each vertex v of degree 2 from a graph by replacing edges (u,v) and (v,w) by an edge (u,w). We also seek to eliminate multiple copies of edges by