Question: Needing help on this question, I will rate :) 4.1 Algorithim Format Algorithm (Function) Name: breadthSearch Input G=(V, E) a graph s, starting node t,

Needing help on this question, I will rate :)

Needing help on this question, I will rate :) 4.1 Algorithim Format

4.1 Algorithim Format

Algorithm (Function) Name: breadthSearch

Input

G=(V, E) a graph

s, starting node

t, terminating node

Output

hasPath = true: there is a path from s to t

= false otherwise

Side effects

N.A.

Auxiliary data

Q: a queue // a node in the queue means its neighbors need to be inspected

// visited[i]: 0 means i is not visited, 1 otherwise

Plan

1. put s into Q, and hasPath := false

2. while Q is not empty

3. take/remove the first element u from Q

4. if u is t

5. hasPath := true

6. break

7. else

8. mark u as visited

9. for each {u, v} \in E // put the un-visited neighbors of u into Q

10. if v is not visited

11. put v into Q

End of algorithm

2. By modifying the breadth first search algorithm in 4.1 of L4 (note that we have a different problem here. A simple copy will not work.), write ONE algorithm in the format used in class to solve the following problem: Given a graph (V, E) and a starting node v, print the nodes of the graph in a breath first manner with respect to v: print v first, then all its neighbors that are not printed yet, then the neighbors (not printed) of the neighbors of v, and so on. 2. By modifying the breadth first search algorithm in 4.1 of L4 (note that we have a different problem here. A simple copy will not work.), write ONE algorithm in the format used in class to solve the following problem: Given a graph (V, E) and a starting node v, print the nodes of the graph in a breath first manner with respect to v: print v first, then all its neighbors that are not printed yet, then the neighbors (not printed) of the neighbors of v, and so on

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!