How Does Depth First Search Work in AI Search?

2.0M views
•
March 31, 2019
by
Gate Smashers
YouTube video player
How Does Depth First Search Work in AI Search?

TL;DR

Depth First Search explores one branch as deeply as possible, then backtracks when it reaches a leaf or cannot continue. It uses a LIFO stack and relies only on present knowledge, making it an uninformed search technique. DFS can be incomplete and non-optimal, particularly when cycles or infinite search spaces prevent it from reaching a goal on another branch.

Transcript

Hello friends welcome to Gate Smashers In today's video we are going discuss DFS that is Depth First Search algorithm in artificial intelligence And in this video you will come to know about all the important points and keyword about DFS Which in competitive exams like NTA NET Or even if you preparing for college or university level exam For artifi... Read More

Key Insights

  • Depth First Search is an uninformed search technique because it works with present knowledge and does not use domain-level estimates, heuristic values, or information about whether the current branch will eventually reach the goal state.
  • DFS uses a stack based on the Last In, First Out rule, while Breadth First Search uses a queue based on the First In, First Out rule. The most recently pushed DFS node is therefore selected next.
  • DFS explores the deepest available node first and backtracks only after reaching a leaf or a node with no unexplored continuation. Breadth First Search follows a different strategy by exploring shallow nodes level by level.
  • DFS traversal order is not necessarily unique because sibling nodes can be pushed onto the stack in different orders. The chosen order changes which branch is explored first, but it does not change the depth-first logic.
  • The example traversal can visit A, C, G, F, B, E, and D when B is pushed before C and D is pushed before E. The stack order causes the last inserted sibling to be removed first.
  • A DFS goal path is reconstructed through parent relationships after the goal is found. If G is the goal in the example, its parent is C and C's parent is A, producing the path from A through C to G.
  • DFS is incomplete when cycles or an infinite search space can trap the search in a loop or an endlessly deep branch. In such cases, a goal located in another direction may never be reached.
  • DFS is non-optimal because its returned solution can have a greater cost than another available solution. Its complexity is written as O(V+E) for nodes and edges, or O(b^d), where b is branching factor and d is depth.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What is Depth First Search in artificial intelligence?

Depth First Search is an uninformed search technique that explores nodes by moving as deeply as possible along one direction before backtracking. It works only with present knowledge and does not use heuristic estimates or domain-level information about whether a selected branch will lead to the goal. For that reason, it is described as blind or brute-force search.

Q: How does Depth First Search use a stack?

Depth First Search stores available nodes in a stack that follows the Last In, First Out rule. When multiple children are pushed, the child added last is removed and visited first. Its children are then added, allowing the search to continue deeper. When no further child exists, an earlier node remains available in the stack for backtracking and exploration.

Q: How does DFS traverse the example tree?

Starting at A, the example pushes B and then C, so C is removed first under the Last In, First Out rule. From C, F and G are added, causing G and then F to be visited. The search subsequently returns to the remaining branch, visits B, and then visits E and D, producing A, C, G, F, B, E, D.

Q: Why can DFS have more than one traversal sequence?

DFS can have multiple traversal sequences because the children of a node may be placed onto the stack in different orders. If B is pushed before C, C is visited first because it was added last. Reversing that insertion order makes B the first branch explored. Both choices retain the defining behavior of moving deeply before backtracking.

Q: How does DFS find and return a goal path?

DFS follows one direction deeply until it encounters the requested goal or reaches a point where it must backtrack. After finding the goal, the path can be returned by following parent relationships. In the example, if G is the goal, G has parent C and C has parent A, so the resulting path is A, C, G.

Q: Why is Depth First Search considered incomplete?

Depth First Search is considered incomplete because it may fail to return a solution even when a goal exists. A graph containing cycles can trap the algorithm in a permanent loop, while an infinite search space can make it descend indefinitely along one branch. A goal located in another direction may consequently never be explored or found.

Q: Why is Depth First Search non-optimal?

Depth First Search is non-optimal because the first solution it discovers is not necessarily the solution with the lowest cost. The algorithm commits to one deep direction according to stack order, so it may return a path whose cost is greater than another existing path. It does not compare heuristic or estimated values when choosing which branch to explore.

Q: What is the time complexity of Depth First Search?

The traversal complexity of DFS is generally written as O(V+E), where V represents the number of nodes and E represents the number of edges that may be visited. From the artificial intelligence search perspective, it is written as O(b^d), where b is the number of possible children per node and d is the goal depth.

Summary & Key Takeaways

  • Depth First Search is an uninformed search technique that explores the deepest available node before considering alternatives. It uses present knowledge rather than heuristic or estimated values. Its behavior resembles blind or brute-force search because it does not know whether the currently selected branch will eventually lead to the desired goal state.

  • DFS uses a stack governed by the Last In, First Out rule. In the example, pushing B and then C causes C to be visited first. The traversal continues through G and F before backtracking toward B, after which E and D are visited. Different push orders can produce different valid sequences.

  • DFS may be incomplete because cycles or an infinite search space can keep it moving along one direction without finding a goal elsewhere. It is also non-optimal because the first solution found may cost more than another solution. Its complexity is expressed as O(V+E), or O(b^d) from an AI perspective.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Gate Smashers 📚