BFS – Breadth First Search using the brute force algorithm as seem in class
Consider the graph below:
1) Represent this graph using adjacency lists. Arrange the neighbors of each vertex in alphabetical order.
– list the triplets for this graph in the form (A, B, 1), where there is a edge from vertex A to vertex B;
– Note that this graph is directed, unlike the one presented in class.
2) Trace the BFS execution by adapting the code to deal with a directed graph (remove lines 14, 15, and 16) and instrumenting it to print every time a vertex is visited and everytime a vertex is enqueued or dequeued.
– Each time a vertex A is visited print: “Vertex A visited” and the current array V;
– Each time a vertex B is enqueued print: “Vertex B enqueued” and the current queue Q;
– Each time a vertex C is dequeued print: “Vertex C enqueued” and the current queue Q.
Reviews
There are no reviews yet.