Question
Write a program that runs either BFS or DFS of a graph as requested. (Note the only difference between queue-based BFS and DFS implementations is
Write a program that runs either BFS or DFS of a graph as requested. (Note the only difference between queue-based BFS and DFS implementations is that FIFO is used for BFS and LIFO is used for DFS. See their pseudocodes in the lecture slides.) Feel free to use Java classes to implement the queues. Your program must prompt for the graph traversal mode (i.e., BFS or DFS) and the start node number, and once they are input, run the traversal against the adjacency list representation of the graph shown below. (This graph is from the lecture slide.) When your program adds nodes to the queue, it must add them exactly in the order of appearance in the linked list (i.e., from left to right), or your program output will be incorrect. Your program code will be tested with different start nodes. At each run, the program should output (i.e., display on the terminal screen) the number of the node visited at each step of the graph traversal. Submit the source codes via Blackboard. Program codes should be working correctly and neatly organized and well commented. Those not working or hard to read will be subject to significant point deduction. Example output of node traversal order:
BFS with the start node 1 discovers the nodes in the following order: 1, 2, 3, 4, 5, 7, 8, 6.
DFS with the start node 1 discovers the nodes in the following order: 1, 3, 8, 7, 5, 6, 4, 2.
1 4 8Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started