Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

his problem concerns distance between vertices in an unweighted graph. I an unwe

ID: 3728827 • Letter: H

Question

his problem concerns distance between vertices in an unweighted graph. I an unweighted graph, the length of a path is the number of edges in that path, and the distance from one vertex v1 to an shortest from traversal. Either breadth-first or depth-first search can be used, although one might be more efficient than the other for a given problem. For each of the following problems, write an algorithm, using clear pseudocode, that solves the problem. The algorithm in each case can be a variation of basic depth-first or breadth-first search. Explain in words how your algorithm works, and say what you can about its run-time efficiency other vertex v2 is the length of the vi to v2. The following problems can be solved using graph a) Given a starting vertex, x, print out every vertex whose distance from is less than or equal to 5. b) Given a starting vertex r, find a vertex y which can be reached from x, and whose distance from x is as large as possible.

Explanation / Answer

Solution:

a)

In this case, we will be starting from vertex x and mark it as visited then we will start visiting its adjacent vertices and also maintaining the count for every vertex in the graph, so when a vertex is visited from mark it as visited and set the count of that vertex to count of the previous vertex + 1, and print that particular vertex if the count value of that vertex is <= 5.

b)

The algorithm is given below:

Algorithm:

The above algorithm will take O(V+E) time to execute, and it will return the farthest vertex from the given vertex v.

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)