Reputation: 145
This is my practice questions for test, i checked about weighted graph and some related materials but got stuck to start so need some ideas on this to start with.
Suppose that you want to get from your house at node s to your mate’s house at node t in a weighted graph G = (V,E,w). But you would like to stop by the local Fish’n Chips place at node u if it is possible to do so without increasing the length of your path by more than 20%.
(a) Describe an efficient algorithm that would determine an optimal s → t path given your preference for stopping at u along the way if doing so is not prohibitively costly. (It should either return the shortest path from s to t or the shortest path from s to t containing u, depending on the situation.) You should make your algorithm run as efficiently as possible
Upvotes: 1
Views: 912
Reputation: 26
Try this Dijkstra algorithm. Find shortest path from s to t, s to u, and u to t. Then, with a little help of mathematics(s to u + u to t > s to t * 1.20) you can see your answer. Cheers.
Upvotes: 1