depth-first-search

Depth-first nested routing in an ASP.NET website

久未见 提交于 2019-12-10 06:20:07
问题 I've been exploring the System.Web.Routing namespace, playing with constraints and such, but I can't see a way to implement this. I'm working on an ASP.NET website ( non-WAP, non-MVC ) using the WebPages/Razor framework. I'm trying to implement a form of "nested routing", where a route can contain child routes that are only attempted if the parent matches; each child attempting to match the "remainder" of the URI. A "depth-first" route match search, if you will. routes.Add(new ParentRoute("

Depth First Search on 2-D array

馋奶兔 提交于 2019-12-10 05:31:25
问题 I am trying to learn DFS by creating a program that navigates my ogre through a maze (2d array).This is similar to a dailyprogramming challenge, but I am doing it with just a 1x1 ogre. My maze: static int[][] maze = { {2,1,0,0,0,0,0,0,0,0}, {0,0,1,0,0,0,0,0,0,0}, {1,0,0,0,0,1,0,1,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,1,1,0,0,0,0,0,0}, {0,0,1,0,0,0,0,1,0,1}, {1,1,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,1,1,0,0,0}, {0,0,0,0,0,1,0,0,0,3}}; Where 2 is my hero (0,0), 3 is my goal (9,9), 1s

Puzzle Game Android DFS algorithm

一世执手 提交于 2019-12-10 00:44:39
问题 I have a android application called Islands and bridges also known as Hashiwokakero The application uses A 2 Dimensional array that spawns the Islands randomly everytime the user restarts the game It form a Matrix with number from 0 to 4 where 0=null and 1-4 = Island There can be 2 bridges comming out of one Island to connect the other , The map at the moment is not solvable. To solve the game the user needs to connect the islands using bridges so if an island = 4 it needs 4 connection to it

How to traverse cyclic directed graphs with modified DFS algorithm

淺唱寂寞╮ 提交于 2019-12-09 14:22:05
问题 OVERVIEW I'm trying to figure out how to traverse directed cyclic graphs using some sort of DFS iterative algorithm. Here's a little mcve version of what I currently got implemented (it doesn't deal with cycles): class Node(object): def __init__(self, name): self.name = name def start(self): print '{}_start'.format(self) def middle(self): print '{}_middle'.format(self) def end(self): print '{}_end'.format(self) def __str__(self): return "{0}".format(self.name) class NodeRepeat(Node): def _

Depth-First search in Python

可紊 提交于 2019-12-09 04:55:08
问题 I'm trying to do a Depth-First search in Python but it's not working. Basically we have a peg-solitaire board: [1,1,1,1,1,0,1,1,1,1] 1's represent a peg, and 0 is an open spot. You must move a peg one at a time TWO SLOTS backwards or forward ONLY to an empty spot. If you jump over another peg in the process it becomes an empty slot. You do this until one peg remains. So basically, a game goes like: [1, 1, 1, 1, 1, 0, 1, 1, 1, 1] [1, 1, 1, 0, 0, 1, 1, 1, 1, 1] [1, 0, 0, 1, 0, 1, 1, 1, 1, 1] [1

Find number of unique routes to specific node using Depth First Search

泪湿孤枕 提交于 2019-12-09 00:46:59
问题 I have a directed graph with vertexes 123456. Using a depth first search, if I wanted to be able to find the number of unique routes from 1-4 (for example), how would I go about doing it? Here is my current DFS. private final Map<Character, Node> mNodes; private final List<Edge> mEdges; private List<Node> mVisited = new ArrayList<>(); int weight; int numberOfPaths; public DepthFirstSearch(Graph graph){ mNodes = graph.getNodes(); mEdges = new ArrayList<>(graph.getEdges()); for(Node node :

Writing a DFS with iterative deepening without recursion

狂风中的少年 提交于 2019-12-08 10:28:34
问题 So currently i have a DFS with the following pseudocode procedure DFS(Graph,source): create a stack S push source onto S mark source while S is not empty: pop an item from S into v for each edge e incident on v in Graph: let w be the other end of e if w is not marked: mark w push w onto S How do I alter this function to accept a third argument that limits the depth of the search? 回答1: Let Node a structure for each node of the graph, add a field called level and then: procedure DFS(Graph

Determining if a graph is K-vertex-connected

Deadly 提交于 2019-12-08 06:33:30
问题 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

Simple implementation of a maze generation method (random DFS)

空扰寡人 提交于 2019-12-08 04:37:24
问题 In an interview, my interviewer asked me this question: Develop a function to generate a random maze This is a quite difficult question to solve in 30min if you don't have solved this question before. On the internet there are many solution but none seems easy. The method should respect this constraint: it should accept the size of the maze (a square maze NxN) it should consist of only Walls and Path to make it simple, the algorithm doens't need to set the entry and the exit I will post the

Algorithm for counting connected components of a graph in Python

依然范特西╮ 提交于 2019-12-08 03:32:27
I try to write a script that counts connected components of a graph and I can't get the right solution. I have a simple graph with 6 nodes (vertexes), nodes 1 and 2 are connected, and nodes 3 and 4 are connected (6 vertexes; 1-2,3-4,5,6). So the graph contains 4 connected components. I use following script to count connected components, but I get wrong result (2). nodes = [[1, [2], False], [2, [1], False], [3, [4], False], [4, [3], False], [5, [], False], [6, [], False]] # 6 nodes, every node has an id, list of connected nodes and boolean whether the node has already been visited