For the digraph given, implement the pseudo algorithms of Breadth-First Search (Traversal) and Depth-First Search (Traversal) in Java or C++. Your implementation should follow the pseudocode provided in the lecture and also as shown below. Use your variables in the implementation. Each must be a separate method. Do not copy somebody else's code.
To complete and test the implementation, you will need to:
a. Make an adjacency-list or adjacency-matrix to save information about nodes and edges.
b. Display the results in the sequence of each of the nodes traversed based on the search (traversal) algorithm.
The only acceptable answers are Java or C++ source code algorithms that work based on the pseudo code in the image below.
breadthFirstSearch() {
for all vertices u
num(u) = 0;
edges = null;
i = 1;
while there is a vertex v such that num(v) == 0
num(v) = i++;
enqueue(v);
while queue is not empty
v = dequeue();
for all vertices u adjacent to v
if num(u) is 0
num(u) = i++;
enqueue(u);
attachEdge(v, u) to edges;
output edges;
}
DFS(v) {
num(v) = i++;
for all vertices u adjacent to v
if num(u) is 0
attachEdge(u, v) to edges;
DFS(u);
}
depthFirstSearch() {
for all vertices v
num(v) = 0;
edges = null;
i = 1;
while there is a vertex v such that num(v) is 0
DFS(v);
output edges;
}