Question: Given the adjacency list for a undirected graph as the following and source vertex as 0 0:8111 2:9 4 3: 8 12 4: 2 1

 Given the adjacency list for a undirected graph as the following

Given the adjacency list for a undirected graph as the following and source vertex as 0 0:8111 2:9 4 3: 8 12 4: 2 1 5: 76 9 6: 5 9 7: 5 8 8: 30107 9: 2 10 65 10: 8 9 4 11: 0 12 12: 3 11 b) Provide path tree by using the following BFS algorithm 9 public class BreadthFirstPaths f 10 private boolean[] marked; / Is a shortest path to this vertex known? private int[] edgeTo; 11 last vertex on known path to this vertex private final int s; I/ source 12 13 1 public BreadthFirstPaths(Graph G, int s) 15 16 17 18 19 20 21 private void bfs (Graph G, int s) marked new boolean[GV( )); edgeTonew int[G.V)]; this.s- s; bfs(G, s) Queue queue new LinkedList ; markedfs] = true; // Mark the source queue.add(s) I/ and put it on the queue. while (queue.isEmpty)) { 23 25 26 27 28 29 30 31 32 int v = queue.remove(); // Remove next vertex from the queue. for (int w: G.adj(v)) if (lmarked[w]) // For every unmarked adjacent vertex, edgeTo(wj v; // save last edge on a shortest path, marked[w] true; // mark it because path is known, queue.add (w) and add it to the queue. 34 35

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!