Depth-First-Search


 

Depth-First-Search

A depth-first-search algorithm exhausts each one direction before trying another direction. The catchphrase you need to remember here is " last-in-first-out " .This result in a search algorithm that goes as deep as possible in the first direction that gets in its way while leaving all other directions for later.

Where it is used ? 

This algorithm is applicable when we are finding the path, like navigation system is based on DFS which provides the path from your location to your destination. And also in solving maze etc.

Pros :

  • At best, this algorithm is the fastest. If it ' lucks out ' and always chooses the right path to the solution (by chance), then depth-first-search takes at least possible time to get to a solution.

Cons:

  • It is possible that the found solution is not optimal.
  • At worst, this algorithm will explore every possible path finding the solution, thus taking the longest possible time before reaching the solution.

Comments