Question: Using java, what would the code be for this pseudocode. I am trying to create a functions of undirected graph. Please help and make sure

Using java, what would the code be for this pseudocode. I am trying to create a functions of undirected graph. Please help and make sure it's working!

Breadth-First Graph Traversal Algorithm.

Let A = (V, E ) be a graph (either directed or undirected).

Initialize FIFO queue Q as being empty.

Initialize each vertex of G as being unmarked.

While there exist unmarked vertices:

Let u be one such unmarked vertex.

Mark u and place it in Q.

While Q is nonempty:

Remove node u from Q.

For every v that is a neighbor/child of u:

If v is unmarked, then mark v and place it in Q

Depth-First Graph Traversal Algorithm.

Let A= (V, E ) be a graph (either directed or undi-

rected).

Initialize stack S as being empty.

Initialize each vertex of A as being unmarked.

While there exist unmarked vertices:

Let u be one such unmarked vertex.

Mark u and push it on to S.

While S is nonempty:

Let u be at the front of S.

Let v be the first unmarked neighbor/child of u.

If v does not exist:

Pop u from S.

Otherwise:

Mark v and push v on to S.

Dijkstras algorithm for a distance traversal of a Graph from source vertex

s

.

Let G = ( V, E, c ) be a network with nonnegative edges, and s V a vertex from which the algorithm begins.

Add the elements of V to an initially empty min Heap H.

Give s priority p(s) = 0, and all other vertices infinite priority.

Set parent(s) = NULL.

While H is nonempty:

Pop node u from H.

Set d(s,u) = p(u).

If p(u) < INFINITY:

For every v that is a child of u:

If d(s,u) + c(u,v) < p(v):

Set p(v) = p(u) + c(u,v), and adjust H.

Set parent(v) = u.

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!