Questions tagged [depth-first-search]

Depth-first search (DFS) is an algorithm for traversing or searching a tree, tree structure, or graph. One starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.

Depth-first search (DFS) is an algorithm for traversing or searching a tree, tree structure, or graph. One starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.

Formally, DFS is an uninformed search that progresses by expanding the first child node of the search tree that appears and thus going deeper and deeper until a goal node is found, or until it hits a node that has no children. Then the search backtracks, returning to the most recent node it hasn't finished exploring. In a non-recursive implementation, all freshly expanded nodes are added to a stack for exploration.

Source.

2567 questions
0
votes
1 answer

pytransitions is there a simple way to get the history of triggered events

class Matter(object): def __init__(self, states, transitions): self.states = states self.transitions = transitions self.machine = Machine(model=self, states=self.states, transitions=transitions, initial='liquid') def…
Xuewen Li
  • 3
  • 1
0
votes
1 answer

parse description fields from JSON response returned by JIRA rest API

I'm trying to parse the JIRA issue fields returned by JIRA REST API v3 but I'm not able to parse the description fields as it is returned in ADF format and the structure or level of child objects are unknown. i have tried to use recursion but it…
0
votes
0 answers

DFS like algorithm to find single source shortest path

I know DFS is not good choice to find shortest path from a source and BFS or dynamic programming solutions are better but i'm just interested in hypothetical situation of speed of particular algorithm.Let's say i have an undirected graph that looks…
Bogdan
  • 47
  • 2
  • 10
0
votes
1 answer

How do I derive the coordinates of the shortest possible paths in a 2D array (similar to leetcode shortest bridge but with coordinates)

I am trying to find the shortest path between two islands(represented by 1) in a 2D array. I want to get the coordinates(row, col) to form possible bridges but with shortest path. So far I have used DFS to identify the islands and their coordinates…
0
votes
1 answer

Depth First Search With Recursion Through Python Dictionary

I'll cut to the chase and say that basically what I'm trying to do is find the longest path of a graph that is represented as a python dictionary. In the dictionary the keys are nodes, and then the values are the lists of nodes that the key has a…
0
votes
0 answers

Difference between using Recursion and stack to implement DFS

What's the difference between using Recursion and stack to implement DFS? probably from the perspective of running time or cache usage Which one is better? Thank you! using stack will spend less time and be more cache-friendly?
qbb
  • 1
  • 1
0
votes
1 answer

How to do DFS and BFS in Adjacency List?

Creating a Adjacency List HashMap > adjList = new HashMap>(); // adding element in Adjacency list (Undirected) void AdjList(Integer a, Integer b){ adjList.putIfAbsent(a, new…
0
votes
1 answer

Incorrect output when trying to query in a depth first search implementation for prolog

I just can't seem to get the correct output - I am supposed to get - ?- dfs([a], X). X = [a, f, i] ; false. But I get - ?- dfs([a], X). X = [a|f] ; % Representation of a tree % choose initial state a arc(a, b). arc(a, f). arc(b, c). arc(b,…
Dramus17
  • 5
  • 3
0
votes
1 answer

Depth first search on Neo4j with filtering on node properties

I would like to perform a depth first search on my graph and so, get all the paths existing from a given node ('N1456' in my example), and all the nodes of theses path must have the same property "PROPERTY_TO_FILTER". Typically, my graph is composed…
NathJ
  • 49
  • 5
0
votes
1 answer

Why does the existence of a Hamilton path in a Directed Acyclic Graph (DAG) show there is single way to topologically order the DAG?

Here is my understanding- we can find a Hamilton path by topologically sorting a DAG and checking if an edge exists between each vertex in this sorted order. And that somehow this shows that this topological order is the only one that can exist. How…
0
votes
2 answers

Reverse Logic programme

I've written code in prolog which will return a list using the depth-first search method. s(a, b). s(a, f). s(b, c). s(b, d). s(b, e). s(f, g). s(f, i). s(i, j). s(i, k). goal(i). searching(Path, Paths, RestOfPaths):- Rest = [Start|], Start ==…
0
votes
1 answer

How to traverse all nodes of a graph using DFS algorithm if the graph is not connected

What's the algorithm to traverse all the nodes of a graph if the graph is not connected? An explanation would be helpful! Thanks
Rocky
  • 11
  • 1
0
votes
1 answer

When I am building nested sets, how do I get the right hand value of a non-leaf node

I'm trying to use a non-recursive depth-first-search approach to read directories and build nested sets. I need to assign left, right, and depth values to the path of the given directory(Files at the same directory level are in no particular…
0
votes
1 answer

Finding if a path exists between two Nodes in a Graph using Depth First Search(DFS) C++

I'm trying to implement the Depth First Search(DFS) suing recursion to return a boolean value if a path exists between two Nodes in a graph. Below is my implementation. The edges input is in the form of a Vector array. I tried debugging the program…
0
votes
2 answers

JavaScript nth degree tree

I need to change the clicked property to true of a parent if all children clicked are true. so in this case ID - 14,15 is having clicked property to true. So, parents having ID 11 clicked has to be made true. If 11,12,14,15 are true then then 4 has…
Srujan R
  • 29
  • 5