Ai Lab Report
Ai Lab Report
Ai Lab Report
Name ID
visited = []
queue = []
# Driver Code
print("Following is the Breadth-First Search")
bfs(visited, graph, 'A') # function calling
Result:
Breadth-First Search is an algorithm used for traversing or searching tree or graph data structures. It starts at a
chosen vertex (or node) of a graph and explores all of the neighboring vertices at the current depth before
moving to the vertices at the next depth level.
SUMMARY
BFS is a widely used graph traversal algorithm that explores all the nodes reachable from a given source node
in the shortest path order. It starts at the source node, explores its neighbors, and then moves to the next level
of neighbors until all nodes are visited. The use of a queue ensures that nodes are visited in the order they are
discovered, resulting in a level-by-level traversal. This algorithm is particularly useful for finding shortest paths
in unweighted graphs and for exploring nodes in a hierarchical structure.
visited = []
queue = []
# Driver Code
print("Following is the Breadth-First Search")
bfs(visited, graph, 'A') # function calling
Output:
SUMMARY
Depth-first search (DFS) is a graph traversal algorithm used to explore a graph or tree data structure. DFS is a
powerful algorithm for traversing or searching graph or tree structures.