Depth First Search

Home

Depth First Search Algorithm

Introduction

The Depth First Search algorithm is a method used to search a graph data structure. From a selected starting node the algorithm searches through a branch until it can go no further. Once an end node is reached on a branch the algorithm back tracks until it reaches another unvisited branch and then continues to search. The algorithm accomplishes backtracking by utilising the stack data structure. The search finishes once the node in the graph is found or all branches and nodes have been visited.

In the above example program the Depth First Search algorithm is used to both generate the maze and to solve it. Once the maze is generated an end point (denoted by the red square) can be selected and the Depth First Search algorithm will be used to discover a path from the start point to the selected end point.

The Algorithm

Bubble Sort UML Activity Diagram

Analysis