User Tools

Site Tools


breadth-first_search_and_depth-first_search

This is an old revision of the document!


Introduction

This tutorial serves as an introduction to path-planning and search algorithms. However, these topics do require prior knowledge of the methods used to program these algorithms. In order to understand these tutorials, you will need to be comfortable with C++, and especially the concepts associated with linked lists, stacks, and queues. An understanding of graph trees and how they are searched is also helpful for these tutorials.

If you want to learn C++ before reading these tutorials, there are a wealth of tutorials on the internet, and many will have different learning impact depending on personal preference. Here is one that I found helpful when learning the basics of C++: http://www.cplusplus.com/doc/tutorial/.

To learn or refresh your knowledge of linked lists, here is a great tutorial for these concepts: http://www.cprogramming.com/tutorial/lesson15.html.

For stacks, I prefer to reference this video: https://www.youtube.com/watch?v=UTgOWWmOVXY.

For queues, I prefer to reference this video: https://www.youtube.com/watch?v=JmQWuEnual4.

To learn about graph trees, here is a great tutorial for these concepts: http://www.tutorialspoint.com/graph_theory/index.htm.

Breadth-First Search (BFS) is a searching algorithm that utilizes the concepts involved with the queue data structure. BFS works by expanding all successors to a node before moving onto analyzing any of those successors. This is known as a first-in, first-out (FIFO) approach. As the search goes through the nodes, it analyzes which nodes are successors, and adds those nodes to the queue as they are found. Then, the search goes back to the queue, and starts to dequeue the nodes in the order that they were added, analyzing those successors and adding them to the queue as well. This method of searching through a graph expands all nodes as it searches, and therefore it casn be fairly inefficient if the goal is very far from the root node. However, tracing the path from root to goal is much easier using this search method.

For a more visual overview of this searching method, reference this tutorial: http://www.pdf-archive.com/2016/05/24/bfsdfstutorial/.

The algorithm for BFS works like this:

1. Put the root node or starting node on queue (s) 2. Examine the queue, whether it is empty or not.

a) If the queue is void, return the failure and stop the searching process.
b) Else, proceed ahead by placing the direct child nodes that have not been discovered yet.

3. If the goal node (g) is found as the first element of the queue, return it as success and stop. 4. Otherwise, removal and expansion of the first element of the queue is required. Place these newly generated offspring at the end of queue at any order. 5. Go back to the step 2 and repeat.

Imagine a graph like this:

breadth-first_search_and_depth-first_search.1464053641.txt.gz · Last modified: 2016/05/23 18:34 by dwallace