Ans to the question no 1:
We have an unweighted graph G = (V, E). Our task is to reach from s to t via u. I think the optimal solution could be: Since we have to pass by vertex u, the best way is to find the shortest path between (s and u) and (u and t) using BFS. Now we have the shortest path from s to t via u. And find the shortest path between s and t using BFS. Now you can choose the best path to return. This algorithm will work in O(V+E) time.
Ans to question no 2:
According to the question, there are two cases in which we have to care if the graph is acyclic then, in that case, we will reach to the parent before the child. And there could be a directed graph like i hates j and j hates i , so in this case ordering of nodes is not possible. So the efficient way to solve the problem is to use topological sorting using DFS, which can handle all the situations. Since the time complexity of DFS is O(V+E), topological sort uses the same approach so the time complexity of the algorithm will be O(m+n).
Problem 1: Shortest Path-ish Suppose that you want to get from vertex s to vertex t in an...
Run the Dijkstra’s algorithm on the directed graph of the following figure 24.6, using vertex t as the source. In the style of Figure 24.6, show the d and ? values and the vertices in set S after each iteration of the while loop. 1 8 10 I 10 14 4 6 4 6 2 3 2 3 4 6 5 5 2 (a) (c) 1 10 13 4 6 (d) (e) Figure 24.6 The execution of Dijkstra's algorithm. The...
SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...