breadth-first-search

inserting into a queue while enumerating it

百般思念 提交于 2019-12-25 01:48:12
问题 I want to do a breadth first search of a tree using a Queue var q = new Queue<T>(); q.Enqueue(Root); foreach(T root in q) { foreach(T t in root.Children) q.Enqueue(t); } However I get a "Collection was modified after the enumerator was instantiated." Exception. Is there a C# type that I can do this with? Edit: a little reading make me thing I might be doing this totally wrong. Is there a way to use a foreach to dequeue from a Queue? this works but is ugly (OMHO) var q = new Queue<T>(); q

DFS and BFS with adjacency matrix counted in Java

泄露秘密 提交于 2019-12-25 01:32:34
问题 Currently trying to build a program that can implement both DFS and BFS in Java by taking in an adjacency matrix from a file and printing out the following info: order that vertices are first encountered, order that vertices become dead ends, number of components, and the tree edges. Here is my code: import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class ProjectDriver { public static int count; public static void main

BFS uninformed search issue

被刻印的时光 ゝ 提交于 2019-12-24 10:17:25
问题 I am trying to avoid an infinite loop and am having trouble figuring out whats wrong. This is supposed to find a solution for a 3x2 puzzle board. I suspect the problem may be with my overridden equals method but I'm not sure. Running into two issues: 1) It keeps re-exploring already explored nodes. 2) The queue is empty before a solution is found, causing an error. Driver class: import java.util.*; public class Driver { public static void main(String[] args){ Node test = new Node(new int[]{1,

Disconnected node during Graph traversal

ぃ、小莉子 提交于 2019-12-23 15:13:48
问题 I have been going through Breadth First Traversal at this link Breadth First Traversal Now what if the graph structure is changed to this The node 3 is now disconnected from the graph. When traversal program is now used, it does'nt display vertex 3. Is there a way where we can dispaly this vertex as well? 回答1: To my understanding, BFS would keep looking for unvisited nodes as long as they exist; however, if this is not done, BFS only visits nodes in the connected component of the initial

Solve Cannibals/Missionaries using breadth-first search (BFS) in Prolog?

隐身守侯 提交于 2019-12-23 13:35:10
问题 I am working on solving the classic Missionaries(M) and Cannibals(C) problem, the start state is 3 M and 3 C on the left bank and the goal state is 3M, 3C on the right bank. I have complete the basic function in my program and I need to implemet the search-strategy such as BFS and DFS. Basically my code is learn from the Internet. So far I can successfuly run the program with DFS method, but I try to run with BFS it always return false. This is my very first SWI-Prolog program, I can not find

Breadth-first search on an 8x8 grid in Java

天大地大妈咪最大 提交于 2019-12-23 07:26:14
问题 What I'm trying to do is count how many moves it takes to get to the goal using the shortest path. It must be done using a breadth first search. I put the 8x8 grid into a 2d array which is filled with one of four chars, E for empty (can move into these spots), B for blocked (can't move here), R for robot (starting point), or G for goal. The algorithm had to check for movable spaces in the order up, left, right, then down, which I believe I've done correctly. After a node is checked it changes

BFS traversal using cypher

穿精又带淫゛_ 提交于 2019-12-23 02:26:32
问题 I need to traverse a directed acyclic graph (DAG) using BFS. I am using neo4j via REST API, so my main way of commuication with neo4j is using Cypher. With Cypher I can retrieve a set of all the paths from a starting node, and from them derive a BFS traversal. I was wondering if there's a simpler way of getting a BFS traversal using Cypher. What I expect as output would be an array of sets of nodes. 回答1: Couldn't you then just order resulting paths after length, maybe take the last node from

Given an “Adjacency Matrix” representation of a an undirected graph BFS on the graph and output the vertex

走远了吗. 提交于 2019-12-23 02:05:30
问题 I can find BFS and DFS values in a two-dimensional array array, but there is no increase in scoring. I could not figure out exactly which part I did wrong. When I print the values that should be, the sort is correct. but the grade is still 0. I am open to your ideas. public class BFS_DFS { public static int[] BFS (int [][] graph) { int[] output = {0}; int start=0; int v=graph.length;//a[][] is adj matrix declared globally boolean visited[]=new boolean[v];//indexing done from 1 to n LinkedList

Pathfinding in JavaFX

佐手、 提交于 2019-12-22 17:59:48
问题 I have created a maze game in JavaFX where a user can create their own maze and play it. The maze is built using buttons with CSS IDs depending on the 2-dimensional array the level is temporarily stored in. The problem arises with the next part of the project. I have created an algorithm which generates a random maze. In order for the level to be possible, I need to check if the maze is solvable (i.e. you can get from the start (0, 3) to the finish (6, 3)). I have created a separate project

Do any POSIX functions or glibc extensions implement a breadth-first file tree walk?

只谈情不闲聊 提交于 2019-12-22 10:49:36
问题 I am writing a daemon that utilizes inotify to monitor file access and it is critical that I don't miss anything on a recursive search. I found this interesting idea and have begun to implement it. ftw() and ftw64() do not use a breadth-first algorithm, its more "pre-order". nftw() gives me the option of depth-first, but I'm worried about races in upper leaves. I'm hoping that I'm missing something, perhaps a GNU extension? Or am I just looking at implementing my own with type safe call backs