depth-first-search

Breadth First Vs Depth First

When Traversing a Tree/Graph what is the difference between Breadth First and Depth first? Any coding or pseudocode examples would be great. ...

Find first null in binary tree with limited memory

I have a binary tree where each node can have a value. I want to find the node in the tree that has value null and is closest to the root. If there are two nodes with the same distance from the root, either will do. I need to minimize the number of read accesses to the binary tree. Assume that working memory is limited to just k node...

Iterative-deepening depth first search using limited memory

This is a follow-up to Find first null in binary tree with limited memory. Wikipedia says that iterative-deepening depth first search will find the shortest path. I would like an implementation that is limited in memory to k nodes and accesses the tree the least number of times. For instance, if my binary tree is: 0 1 ...

Finding biggest area of adjacent numbers in a matrix

This is NOT a homework. I'm a beginner in programming, and also this is my first post here - please bear with me. I was not able to find similar questions posted here. In a beginner's book, I found the following issue: # Find the biggest area of adjacent numbers in this matrix: 1 3 2 2 2 4 3 3 3 2 4 4 4 3 1 2 3 3 #--> 13 times '3' 4...

depth-first-search

I implemented a depth-first-search in c# based on information I found on the net and old java books and I used the Node and NodeList and Graph from the msdn site. How can one modify the DFS or BFS to check for particular weight? ...

Depth first search using java

I want to implement DFS (Depth first search) and BFS using java. Does java have a built in tree data structure that I can use readly? Or any other thing that I can use? ...

What is breadth-first search useful for?

Usually when I've had to walk a graph, I've always used depth-first search because of the lower space complexity. I've honestly never seen a situation that calls for a breadth-first search, although my experience is pretty limited. When does it make sense to use a breadth-first search? UPDATE: I suppose my answer here shows a situati...

Manage isVisited method with double values

I am working on implementing a recursive depth first search, my issue is maintaining visited elements in my ArrayList. I have double values but the way using a boolean[], I have to type cast it to int, once you do that you no longer work with the same value. Here is what I have so far, any help would be greatly appreciate public void...

Complexity of finding all simple paths using depth first search?

Thanks to everyone replying with ideas and alternate solutions. More efficient ways of solving problems are always welcome, as well as reminders to question my assumptions. That said, I'd like you to ignore for a moment what problem I'm trying to solve with the algorithm, and just help me analyze the big-Oh complexity of my algorithm as...

revisiting nodes during DFS and controlling infinite cycles

I am implementing DFS on a weighted directed graph in the following way: public class DFSonWeightedDirectedGraph { private static final String START = "A"; private static final String END = "C"; private int pathLength = 0; private int stops = 0; public static void main(String[] args) { //this is a direc...

extra space for recursive depth-first search to store paths

I am using depth-first search to identify paths in a directed weighted graph, while revisiting nodes that belong to a cycle, and setting cutoff conditions based on total distance traveled, or stops from the source node. As I understand, with recursion an explicit stack structure is not required for depth first search, so I was wonderin...

Depth-First search in Python

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....

Best and easiest algorithm to search for a vertex on a Graph?

Hi, After implementing most of the common and needed functions for my Graph implementation, I realized that a couple of functions (remove vertex, search vertex and get vertex) don't have the "best" implementation. I'm using adjacency lists with linked lists for my Graph implementation and I was searching one vertex after the other unti...

Pruning: When to Stop?

When does pruning stop being efficient in a depth-first search? I've been working on an efficient method to solve the N-Queens problem and I'm looking at pruning for the first time. I've implemented it for the first two rows, but when does it stop being efficient? How far should I prune to? ...

Depth First Search Basics

I'm trying to improve my current algorithm for the 8 Queens problem, and this is the first time I'm really dealing with algorithm design/algorithms. I want to implement a depth-first search combined with a permutation of the different Y values described here: http://en.wikipedia.org/wiki/Eight_queens_puzzle#The_eight_queens_puzzle_as_an_...

breadth first or depth first search

I know how this algorithm works, but cant decide when to use which algorithm ? Are there some guidelines, where one better perform than other or any considerations ? Thanks very much. ...

Why DFS and not BFS for finding cycle in graphs.

Predominantly DFS is used to find a cycle in graphs and not BFS. Any reasons? Both can find if a node has already been visited while traversing the tree/graph. ...

How can I store data in a table as a trie? (SQL Server)

Hi, To make things easier, the table contains all the words in the English dictionary. What I would like to do is be able to store the data as a trie. This way I can traverse the different branches of the trie and return the most relevant result. First, how do I store the data in the table as a trie? Second, how do I traverse the tr...

Creating a Maze using Java

Im using Java to create a maze of specified "rows" and "columns" over each other to look like a grid. I plan to use a depth-first recursive method to "open the doors" between the rooms (the box created by the rows and columns). I need help writing a openDoor method that will break the link between rooms. ...

Will DFS from every node give all cycles in a directed graph

Hi, I want to find all the cycles in a directed graph. Starting Depth-first search from one node will find some cycles(finding back-edges). So, i applied dfs to all the nodes in the graph(i.e. each time the root is a different node). I am able to get all the cycles using this(by eliminating duplicate ones). But, i am not sure whether thi...