22PEOIT4C Session 4 Breath First Search & Depth First Search.pptx
1.
12/06/2025
DEPARTMENT OF SPECIALBATCH (ET)
IV B. Tech -I Semester
ARTIFICAL INTELLIGENCE
SUBJECT CODE: 22PEOIT4C
AcademicYear : 2024-2025
by Dr.M.Gokilavani
GNITC
Department of SB-ET 1
2.
12/06/2025 Department ofSB-ET
TEXTBOOK:
• Artificial Intelligence A modern Approach, Third Edition, Stuart
Russell and Peter Norvig, Pearson Education.
REFERENCES:
• Artificial Intelligence, 3rd
Edn, E. Rich and K.Knight (TMH).
• Artificial Intelligence, 3rd
Edn, Patrick Henny Winston, Pearson
Education.
• Artificial Intelligence, Shivani Goel, Pearson Education.
• Artificial Intelligence and Expert Systems- Patterson, Pearson
Education.
2
3.
12/06/2025 Department ofSB-ET
22PEOIT4C ARTIFICAL INTELLIGENCE
UNIT – I
Syllabus
Introduction to AI, Intelligent Agents, problem-Solving Agents,
Searching for Solutions, Uninformed Search Strategies: Breadth-
first search, Uniform cost search, Depth-first search, Iterative
deepening Depth-first search, Bidirectional search, Informed
(Heuristic) Search Strategies: Greedy best-first search, A* search,
Heuristic Functions, Beyond Classical Search: Hill-climbing
search, Simulated annealing search, Local Search in Continuous
Spaces.
3
4.
12/06/2025 Department ofSB-ET
Properties of Search Algorithms
Following are the four essential properties of search algorithms to compare the
efficiency of these algorithms:
• Completeness: A search algorithm is said to be complete if it guarantees to
return a solution if at least any solution exists for any random input.
• Optimality: If a solution found for an algorithm is guaranteed to be the
best solution (lowest path cost) among all other solutions, then such a
solution for is said to be an optimal solution.
• Time Complexity: Time complexity is a measure of time for an algorithm
to complete its task.
• Space Complexity: It is the maximum storage space required at any point
during the search, as the complexity of the problem.
4
UNIT - I LECTURE - 04
5.
12/06/2025 Department ofSB-ET
Types of search algorithms
Based on the search problems we can classify
the search algorithms into
– uninformed (Blind search) search and
– informed search (Heuristic search) algorithms.
5
UNIT - I LECTURE - 04
12/06/2025 Department ofSB-ET
Uninformed/Blind Search
•Uninformed search applies a way in which search tree is searched
without any information about the search space like initial state
operators and test for the goal, so it is also called blind search.
•Don’t have any domain knowledge .
•It examines each node of the tree until it achieves the goal node.
It can be divided into five main types:
– Breadth-first search
– Uniform cost search
– Depth-first search
– Iterative deepening depth-first search
– Bidirectional Search
7
UNIT - I LECTURE - 04
8.
12/06/2025 Department ofSB-ET
Informed Search
• Informed search algorithms use domain knowledge. In an informed
search, problem information is available which can guide the search.
• Informed search strategies can find a solution more efficiently than
an uninformed search strategy. Informed search is also called a
Heuristic search.
• A heuristic is a way which might not always be guaranteed for best
solutions but guaranteed to find a good solution in reasonable time.
• An example of informed search algorithms is a traveling salesman
problem.
• Greedy Search
• A* Search
8
UNIT - I LECTURE - 04
9.
12/06/2025 Department ofSB-ET 9
Breadth-first Search
• Breadth-first search is the most common search strategy for
traversing a tree or graph. This algorithm searches breadthwise
in a tree or graph, so it is called breadth-first search.
• BFS algorithm starts searching from the root node of the tree
and expands all successor node at the current level before
moving to nodes of next level.
• The breadth-first search algorithm is an example of a general-
graph search algorithm.
• Breadth-first search implemented using FIFO queue data
structure.
UNIT - I LECTURE - 04
10.
12/06/2025 Department ofSB-ET
Algorithm
• Step 1: SET STATUS = 1 (ready state) for each node in G
• Step 2: Enqueue the starting node A and set its STATUS = 2
(waiting state)
• Step 3: Repeat Steps 4 and 5 until QUEUE is empty
• Step 4: Dequeue a node N. Process it and set its STATUS = 3
(processed state).
• Step 5: Enqueue all the neighbours of N that are in the ready
state (whose STATUS = 1) and set
their STATUS = 2
(waiting state)
[END OF LOOP]
• Step 6: EXIT
10
UNIT - I LECTURE - 04
12/06/2025 Department ofSB-ET
• In the example given below, there is a directed graph having 7
vertices.
• In the above graph, minimum path 'P' can be found by using
the BFS that will start from Node A and end at Node E.
• The algorithm uses two queues, namely QUEUE1 and
QUEUE2.
• QUEUE1 holds all the nodes that are to be processed, while
QUEUE2 holds all the nodes that are processed and deleted
fromQUEUE1.
12
UNIT - I LECTURE - 04
12/06/2025 Department ofSB-ET
Applications of BFS algorithm
• BFS can be used to find the neighboring locations from a
given source location.
• BFS can be used in web crawlers to create web page indexes.
• BFS is used to determine the shortest path and minimum
spanning tree.
16
UNIT - I LECTURE - 04
17.
12/06/2025 Department ofSB-ET
DFS (Depth First Search) algorithm
• It is a recursive algorithm to search all the vertices of a tree
data structure or a graph.
• The depth-first search (DFS) algorithm starts with the initial
node of graph G and goes deeper until we find the goal node
or the node with no children.
• Because of the recursive nature, stack data structure can be
used to implement the DFS algorithm.
• The process of implementing the DFS is similar to the BFS
algorithm.
17
UNIT - I LECTURE - 04
18.
12/06/2025 Department ofSB-ET
The step by step process to implement the DFS traversal is given as
follows -
• First, create a stack with the total number of vertices in the graph.
• Now, choose any vertex as the starting point of traversal, and push
that vertex into the stack.
• After that, push a non-visited vertex (adjacent to the vertex on the
top of the stack) to the top of the stack.
• Now, repeat steps 3 and 4 until no vertices are left to visit from the
vertex on the stack's top.
• If no vertex is left, go back and pop a vertex from the stack.
• Repeat steps 2, 3, and 4 until the stack is empty.
18
UNIT - I LECTURE - 04
19.
12/06/2025 Department ofSB-ET
Algorithm
• Step 1: SET STATUS = 1 (ready state) for each node in G
• Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting
state)
• Step 3: Repeat Steps 4 and 5 until STACK is empty
• Step 4: Pop the top node N. Process it and set its STATUS = 3 (processed state)
• Step 5: Push on the stack all the neighbors of N that are in the ready state
(whose STATUS = 1) and set their STATUS = 2 (waiting state)
• [END OF LOOP]
• Step 6: EXIT
19
UNIT - I LECTURE - 04
12/06/2025 Department ofSB-ET
Applications of DFS
• DFS algorithm can be used to implement the topological
sorting.
• It can be used to find the paths between two vertices.
• It can also be used to detect cycles in the graph.
• DFS algorithm is also used for one solution puzzles.
• DFS is used to determine if a graph is bipartite or not.
22
UNIT - I LECTURE - 04
12/06/2025 Department ofSB-ET
Topics to be covered in next session 5
• Uniform cost search & Iterative deepening Depth-
first search
25
Thank you!!!
UNIT - I LECTURE - 04