Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago