Run pip3 install
to download modules.
python3 main.py
to run program.
Graph Traversal
Graph Theory
DFS & BFS Algorithms
Our project aims at simulating graph traversal techniques using BFS and DFS algorithms.
-
The DFS algorithm works as follows:
- a. Start by putting any one of the graph's vertices on top of a stack.
- b. Take the top item of the stack and add it to the visited list.
- c. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to the top of stack.
- d. Keep repeating steps 2 and 3 until the stack is empty.
-
The BFS algorithm works as follows:
- a. Start by putting any one of the graph's vertices at the back of a queue.
- b. Take the front item of the queue and add it to the visited list.
- c. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to the back of the queue.
- d. Keep repeating steps 2 and 3 until the queue is empty.