depth-first-search

sort predicate to have nodes sorted in Depth First Search order

痴心易碎 提交于 2019-12-12 02:43:47
问题 I have a list of nodes, where each of the nodes belong to one or multiple trees. (they do not necessarily share a common ancestor) I want to sort the nodes in the same order I would find them when doing a Depth First Search. Let say I have a predicate for sorting tree roots together, and another predicate to sort children of a common parent together. Each node have a Parent accessor, and a children enumerator. I want to avoid using the Children enumeration for performance reasons (if possible

Finding cycles Depth-first-search

落爺英雄遲暮 提交于 2019-12-11 23:17:47
问题 I am trying to repair graphs by deleting one edges. The only problem I am running in to is, when there are multiple cycles in the graph for example: 0 3, 2 3, 0 2, 1 2, 3 1. This can be fixed by extracting 3 1, but how do I let the program no that 3 1 is the edge that has to be removed? Any suggestions? :) Formatted code from comment... ... else if (backedges.Count > 1) { foreach (Side side in backedges) { Node end = Side.node2; Node begin = Side.node1; List<Side> allsidesycle = new List<Side

Maze shortest path using recursion

允我心安 提交于 2019-12-11 19:23:56
问题 First of all I want to note that I posted this same question before and did not found a right answer, so sorry for repeating question. Note that I am required to use recursion here. I am aware that shortest path is usually found using BFS, which is not recursive, but I need to know how can this be done recursively. I am working on a rouge game and one of my monsters behaves like this. In a maze, if monster can reach the player in 15 or less steps, it makes the most optimal move possible. In

Depth First Iterative deepening algorithm returning no results (in java)

非 Y 不嫁゛ 提交于 2019-12-11 18:18:57
问题 I have a search algorithm that is supposed to parse the entire tree, find all results that could match a search query, and return them all as a list. I realize this isn't quite the point of the algorithm, but I'm doing this as a test with breadth first and depth first searches to see what is fastest by timing them. The other two searches work as intended, but when I enter the same search information as my goal for the DFID search i get an empty list. So I know my data is right, just something

Depth First Search in Parallel

删除回忆录丶 提交于 2019-12-11 17:35:39
问题 I have a huge binary Tree (each Node has a Pass and Fail Node) and I want to traverse this Tree in order to get all possible Paths using DFS. Since the tree is huge, the time taken to DFS using a single thread is taking very long time. So in order to solve this problem, I am now considering doing parallel DFS. The basic idea is below. Start with a single thread and do a normal DFS, as this hits a node, spawn a new thread that start with the fail node as the start node and pass to that call

Graph DFS Algorithm NullPointerException

只愿长相守 提交于 2019-12-11 16:28:24
问题 I have simply exercises to school in java but eclipse all time display error NullPointerException . I must write a program which can read data from file (vertex), next from this data I should count graph size and next I must use DFS algorithm to count consistent components. I know that my code is not good but I am still learning java (and english :P ). test.txt 0 1 0 4 1 2 1 4 1 5 1 8 1 11 2 6 3 1 3 7 4 8 5 2 5 8 6 5 6 7 6 9 8 4 9 5 9 7 10 8 10 11 11 8 11 9 11 12 12 3 12 6 12 9 Exception

Dfs algorithm that decides if a directed graph has a unique topological sort

帅比萌擦擦* 提交于 2019-12-11 15:56:59
问题 I'm trying to struct an algorithm that uses DFS for the purpose of deciding whether a given directed graph has unique topological sort or not. My approach to the problem is that only a specific graph has a unique topological sort. And that graph is a chain like graph, in which all of the vertices are connected to each other in one line. My dilemma is how to do an efficient DFS algorithm, and what exactly should I check. 回答1: From here a digraph has a unique topological ordering if and only if

Able to find path using DFS but not able specify the right directions to Pacman _ Python

房东的猫 提交于 2019-12-11 10:05:17
问题 I am working on an assignment found on an AI course page at berkley website for fun. I need to write a depth-first search for the pacman game so that it can find its path.The problem is the pacman gets stuck. I'll paste the code first to make what I am saying more clear : import util class SearchProblem: """ This class outlines the structure of a search problem, but doesn't implement any of the methods (in object-oriented terminology: an abstract class). You do not need to change anything in

2D array traversal to get distinct 7 digit number combos

匆匆过客 提交于 2019-12-11 07:54:24
问题 I ran into a tricky question from an interview prep book which goes.. You have a 3 by 3 matrix containing integers 1 to 9 as shown below 1 2 3 4 5 6 7 8 9 How do you get unique 7 digit number combos with the first numbers all starting with 4 (matrix[1][0]). The traversal is meant to be like that of a rook on a chess board.. 1 way either horizontally or vertically...(Having 4125874 is valid 7 digit combo btw). I tried writing some code and doing regular 2D matrix traversal with a boolean

Detect if the element im currently in is the youngest son/grandson/grandgrand son of an element

梦想的初衷 提交于 2019-12-11 07:49:48
问题 I am looping around span elements which belongs to frag class. I wanted to detect if the frag element im currently in is the youngest son/grandson/grandgrand son(from left to right) of the a span element which belongs to frag class and belongs to cond class and has an "if" or "else if" in its text contenteditable div (textarea) if( ((b>0) && (b<10)) || b==15 ) HTML equivalent <div id="board"> <div> <span class="frag cond">if<span class="openParen bm1">(</span> <span class="frag cond"><span