0% found this document useful (0 votes)
39 views

Artificial Intelligence: Anurag Upadhyay

The document discusses and compares breadth-first search (BFS) and depth-first search (DFS) algorithms. BFS searches the shallowest nodes first by exploring the neighbors of the initial node then moving outward in levels, using a queue. DFS prioritizes searching deeper nodes first by exploring along each branch as far as possible before backtracking, using a stack. While DFS uses less memory, BFS is guaranteed to find the shortest solution if one exists. The document provides pseudocode for the algorithms and analyzes their characteristics and performance on the water jug problem.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Artificial Intelligence: Anurag Upadhyay

The document discusses and compares breadth-first search (BFS) and depth-first search (DFS) algorithms. BFS searches the shallowest nodes first by exploring the neighbors of the initial node then moving outward in levels, using a queue. DFS prioritizes searching deeper nodes first by exploring along each branch as far as possible before backtracking, using a stack. While DFS uses less memory, BFS is guaranteed to find the shortest solution if one exists. The document provides pseudocode for the algorithms and analyzes their characteristics and performance on the water jug problem.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Artificial Intelligence

Anurag Upadhyay

Breadth First Search


Algorithm:
1. Create a variable called NODE-LIST and set it to initial state 2. Until a goal state is found or NODE-LIST is empty do
a. Remove the first element from NODE-LIST and call it E. If NODE-LIST was empty, quit b. For each way that each rule can match the state described in E do:
i. Apply the rule to generate a new state ii. If the new state is a goal state, quit and return this state

Depth First Search


Algorithm:
1. 2. If the initial state is a goal state, quit and return success Otherwise, do the following until success or failure is signaled:
a. Generate a successor, E, of initial state. If there are no more successors, signal failure. b. Call Depth-First Search, with E as the initial state c. If success is returned, signal success. Otherwise continue in this loop.

Characteristics of BFS
BFS will not get trapped exploring a blind alley. If there is a solution, BFS is guaranteed to find it. If there are multiple solutions, then a minimal solution will be found. Queue data structure is used. As it has to remember each node at a level it takes more memory and is slower.

Characteristics of DFS
DFS requires less memory as only the nodes on the current path are stored. By chance, DFS may find a solution without examining much of the search space at all. Uses Stack data structure. Takes less memory and is faster. Better if we just have to determine if there is a solution present or not.

BFS Tree for Water Jug problem


(0,0 )

(4,0 ) (0,0 ) (1,3 ) (4,3 )

(0,3 ) (0,0 ) (3,0 )

(4,3 )

DFS Tree for Water Jug problem


(0,0 )

(4,0 )

(4,3 )

You might also like