Artificial Intelligence Lab Report 02
Artificial Intelligence Lab Report 02
Lab Report NO # 02
Course Title: Artificial Intelligence Lab
Course Code: CSE 316 Section: 221_D4
Write a python code to perform bfs traversal on the given graph and print the order of
the nodes.
Student Details
Name ID
Write a python code to perform bfs traversal on the given graph and print the order of the
nodes.
2. OBJECTIVES
Understand BFS Algorithm: Learn the working principle of BFS and how it explores nodes level by
level.
Implement BFS in Python: Write an efficient BFS traversal using a queue-based approach.
Graph Representation: Represent graphs using adjacency lists for efficient traversal.
Explore Connectivity: Identify reachable nodes from a given starting node.
Optimize Traversal: Use sets or Boolean arrays to track visited nodes and avoid redundant processing.
Analyze Time Complexity: Understand that BFS runs in O(V + E) time complexity, where V is vertices
and E is edges.
Apply BFS to Real-World Problems: Utilize BFS for shortest path finding, network broadcasting, and
AI search algorithms.
Compare BFS and DFS: Highlight differences between BFS and Depth-First Search (DFS) in terms of
traversal and applications.
Continue dequeuing and processing nodes until all reachable nodes are visited.
4. TEST RESULT / OUTPUT
5. ANALYSIS AND DISCUSSION
The problem involves implementing Breadth-First Search (BFS) traversal on a directed graph,
starting from node 0. BFS is an efficient graph traversal algorithm that explores all neighbors of a
node before moving to the next level. The algorithm follows a FIFO (First-In-First-Out) approach
using a queue, ensuring that nodes are visited in the correct order. An adjacency list representation is
used for the graph, making traversal efficient in terms of space and time. The time complexity is O(V
+ E), where V is the number of vertices and E is the number of edges, since each node and edge is
processed once. The space complexity is O(V), as it requires storage for the visited nodes and queue.
The BFS traversal order for the given graph is 0 → 2 → 1 → 3 → 4 → 5, ensuring that all reachable
nodes are visited systematically.
6. Summary
The problem involves implementing BFS traversal on a directed graph starting from node 0. BFS
explores nodes level by level using a queue and tracks visited nodes with a set, ensuring an efficient
O(V + E) time complexity. The traversal order is 0 → 2 → 1 → 3 → 4 → 5, covering all reachable
nodes. BFS is widely used in shortest pathfinding, network traversal, and AI search algorithms,
making it a crucial technique for structured graph exploration.