depth-first-search

Singly connected Graph?

无人久伴 提交于 2019-12-08 01:36:19
问题 A singly connected graph is a directed graph which has at most 1 path from u to v ∀ u,v. I have thought of the following solution: Run DFS from any vertex. Now run DFS again but this time starting from the vertices in order of decreasing finish time. Run this DFS only for vertices which are not visited in some previous DFS. If we find a cross edge in the same component or a forward edge, then it is not Singly connected. If all vertices are finished and no such cross of forward edges, then

What if I do not use G transpose in calculating Strongly Connected Components?

不打扰是莪最后的温柔 提交于 2019-12-07 19:35:53
问题 I am reading Introduction to Algorithms. In 22.5 Strongly Connected Component, the algorithm STRONGLY-CONNECTED-COMPONENT(G) is defined as: Call DFS(G) to compute finishing times u.f for each vertex u Compute G transpose Call DFS(G transpose), but in the main loop of DFS, consider the vertices in order of decreasing u.f(as computed in line 1) Output the vertices of each tree in the depth-first forest formed in line 3 as a separate strongly connected component If I change the alogrithm to just

Network X , which depth searching option to select for this use?

China☆狼群 提交于 2019-12-07 18:58:31
I am trying to ensure a global correct orientation of my normals. I.e make sure they point outwards everywhere. This is my method: I have a coordinate list x y c n . At each point in coordinate list I create edges from the point to its 5 nearest neighbours. I Weight each edge with ( 1-n1.n2 ). Compute a minimal spanning tree. Traverse this tree in depth first order. Start traversing at the point with the greatest z value, force the normal of this point to be orientated towards the positive z axis. Assign orientation to subsequent points that are consistent with their preceeding point, for

C++ Depth First Search (DFS) Implementation [closed]

邮差的信 提交于 2019-12-07 18:51:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am trying to implement the following DFS code described at Competitive Programming 1 book: #include <cstdio> #include <vector> using namespace std; #define MAX 10 #define DFS_BLACK 1 #define DFS_WHITE -1 typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; vi dfs_num; vector<vii> adj(MAX)

Finding all possible paths in graph

纵然是瞬间 提交于 2019-12-07 11:43:14
问题 I'm looking for some algorithm which will help me find all possible paths in a graph. Everything I found so far is not fully satisfying. Let's imagine we have a graph (tree) like this one: And let's use some algorithm like Breadth-First Search or Depth-First Search . In return we'll get something like 1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9 Which is how we go through this tree and this is not what I'm looking for. I'd love to get all paths, like: 1 1, 2 1, 2, 4 1, 2, 5 1, 2, 6 1, 3

graph - How to avoid reprocessing same edge twice in Depth First Search?

我与影子孤独终老i 提交于 2019-12-07 06:50:43
问题 The Algorithm Design Manual describes BFS and DFS quite well. The code for dfs in the book has a problem when deciding whether or not to avoid double processing edges. I found the Errata and applied the errata to the code, but still I think the refined code has a problem of checking double processing edges. I paste the refined code as follows: dfs(graph *g, int v) { edgenode *p; int y; if (finished) return; discovered[v] = TRUE; time = time + 1; entry_time[v] = time; process_vertex_early(v);

Determining if a graph is K-vertex-connected

泪湿孤枕 提交于 2019-12-06 16:03:00
I'm looking to come up with an polynomial time algorithm that takes input in the form of a graph, G, and an integer, K, and determines whether G is K-vertex connected. I'm thinking that this would likely utilize Depth First Search. I can see how it could be none with a none-polynomial solution, i.e. just deleting K random vertices, running DFS to check for connectivity, and then doing it again with a different group of vertices. A run time of ~O(n^K) is a little much though, and it is apparently possible to bring this down to polynomial time. Any idea what I'm missing here? I imagine it has

Graph C implementation - Depth first search

走远了吗. 提交于 2019-12-06 16:00:20
问题 I am trying to implement depth first search algorithm using adjacency list representation of graphs. Here is my code: #include<stdio.h> #include<stdlib.h> struct edge { int vertexIndex; struct edge *edgePtr; }edge; struct vertex { int vertexKey; int visited; struct edge *edgePtr; }vertex; void insertVertex(struct vertex *g, int vertexKey, int *vertexCount) { g[*vertexCount].vertexKey=vertexKey; g[*vertexCount].edgePtr=NULL; g[*vertexCount].visited=0; (*vertexCount)++; } void insertEdge(struct

how find fields of all member variables contained in java bean

痞子三分冷 提交于 2019-12-06 15:33:51
问题 I want to make a GUI using Java in which a user can select a bean, edit its fields, and then add an instance of the created bean to a queue. My question though is about accessing the fields. I have a class MyCompositeObject that inherits from MyParentObject. The MyParentObject is composed of multiple beans, each being composed of more beans. The class MyCompositeObject is also composed of beans. I want to find all accessible fields from MyCompositeObject. Class MyParentObject { MyObjectOne

Same result for two arrays of counters of different algorithms

旧街凉风 提交于 2019-12-06 14:45:34
I'm trying to build up a program comparing number of strokes of algorithms BFS, DFS, A* (which has two heuristics) on a game of fifteen. My counter count the same result for the two arrays of counters of BFS and DFS and both A*. Yet, I'm using actually using four different arrays from a main (class Project) and I'm assigning four different variables for those strokes. The part of the code that isn't right is, to my mind, a while loop which explores the son of a vertice as far as possible (for BFS) or discovering each following nodes (for BFS). The difference, which is of the utmost importance,