AI LAB (2) SS Organized
AI LAB (2) SS Organized
2. Task to be Done:
Create a directed graph with multiple nodes and edges.
Implement the Depth-First Search (DFS) algorithm.
Visualize the graph structure using the NetworkX library.
Verify the traversal output by comparing it with the expected DFS order.
3. Algorithm/Flowchart
Algorithm for DFS
1. Initialize a visited list to keep track of visited nodes.
2. Define a recursive function:
o If the current node is not visited:
Add it to the visited list.
Recursively call the function for all adjacent nodes (neighbors).
3. Start the traversal from the root node.
4. Continue until all reachable nodes are visited.
4. Code for Experiment/Practical:
5. Result/Output/Writing Summary
DFS Traversal Output
The DFS traversal for the given graph starting from node 'A' is:
Graph Visualization:
Learning Outcomes (What I Have Learned):
1. Gained a solid understanding of the DFS algorithm and its recursive nature.
2. Learned how to implement DFS on a graph represented as an adjacency list.
3. Understood the process of visualizing graphs using the NetworkX library.
4. Observed the difference between exploring nodes depth-first versus breadth-first.
5. Improved problem-solving skills by implementing recursive graph traversal techniques.