Question

This is a graph problem. Sandy lives in the city, 'S', and Tom lives in the...

This is a graph problem. Sandy lives in the city, 'S', and Tom lives in the city, 'T'. Now, there is a city, 'M' where they can both meet so that the travel time minimized for both. How do we find the city, 'M' in a graph of cities where vertices represent cities and edge weight represent travel time between them?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The city M will be the city for which the absolute difference between the time taken by tom and sandy to travel to M is minimum

1)Use shortest path algorithm like dijkstras to find minimum time taken to travel from city S to all other cities and from city T to all other cities

2)Now traverse each city and find absolute value of time taken from city S to that city and time taken from city T to that city

3)The city for which the value calculated in above step is minimum is the answer.

pseudo code for dijkstras

Let graph be G(V,E)

function Dijkstra(G, s):

for each vertex v in Graph:

dist[v] = inf //set distance to each city as infinity

dist[s] = 0 //distance of source is 0

Q =V

while Q is not empty

u = node with minimum dist[]

Q.remove(u)

for v neighbour u and v is in Q

dist[v]=min(dist[v],dist[u]+distance_between(u,v)) / /where v has not yet been removed from Q.

return dist[]

dist_from_T=dijkstra(G,T)

dist_from_S=dijkstra(G,S)

ans=1//assuming the optimum city is 1st city

for each city in G

if abs(dist_from_T[city]-dist_from_S[city]))<abs(dist_from_T[ans]-dist_from_S[ans]))

ans=city

print ans

If you have more doubt please connect in comment section.Please do upvote

Add a comment
Know the answer?
Add Answer to:
This is a graph problem. Sandy lives in the city, 'S', and Tom lives in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Due: April 15, 2019 Instructions: Complete the assignment on a separate sheet of paper. Show all ...

    Due: April 15, 2019 Instructions: Complete the assignment on a separate sheet of paper. Show all work, write tull sentences, and justify all steps and conclusions unless told otherwise. You may use a computer as an aid, but be sure to include supporting work. 1. Is there a path of length 5 from a to d? If so, given an example. Is this path simple? 2. For each of the items below, write a paragraph addressing each question. (a) Create...

  • 1. In the following graph, suppose that the vertices A, B, C, D, E, and F represent towns, and th...

    question 1 and 2 please, thank you. 1. In the following graph, suppose that the vertices A, B, C, D, E, and F represent towns, and the edges between those vertices represent roads. And suppose that you want to start traveling from town A, pass through each town exactly once, and then end at town F. List all the different paths that you could take Hin: For instance, one of the paths is A, B, C, E, D, F. (These...

  • Suppose that we are given a model of a city as a directed, weighted graph G...

    Suppose that we are given a model of a city as a directed, weighted graph G = (V, E); w : E → R≥0, where we have n neighbourhoods and m streets, represented by the vertices and edges respectively. We will assume that the streets are one-way. We are also given that k of these neighbourhoods have fire stations installed. We want to find the nearest fire station for each neighbourhood, where we measure the distance from the fire station...

  • Juliet lives in a small town in Wisconsin called Verona. A stylized map of Verona is...

    Juliet lives in a small town in Wisconsin called Verona. A stylized map of Verona is presented as a directed graph N(V, A) in Figure 1. The number on the arc represent the travel time incurred if traveling the corresponding piece of road. All roads are two-way streets and we assume that travel times are equal in both directions. 4 Figure 1: Network representation of Verona, WI Juliet has been invited to an exciting party, where she knows she will...

  • The Traveling Salesman problem (TSP) is famous. Given a list of cities and the distances in betwe...

    The Traveling Salesman problem (TSP) is famous. Given a list of cities and the distances in between them, the task is to find the shortest possible tour that starts at a city, visits each city exactly once and returns to a starting city. A particular tour can be described as list of all cities [c1,c2, c3, ,cn] ordered by the position in which they are visited with the assumption that you return from the last city to the start. This...

  • Question 1: Given an undirected connected graph so that every edge belongs to at least one...

    Question 1: Given an undirected connected graph so that every edge belongs to at least one simple cycle (a cycle is simple if be vertex appears more than once). Show that we can give a direction to every edge so that the graph will be strongly connected. Question 2: Given a graph G(V, E) a set I is an independent set if for every uv el, u #v, uv & E. A Matching is a collection of edges {ei} so...

  • Updating an MST when an edge weight changes. You have a graph G= (V, E) with...

    Updating an MST when an edge weight changes. You have a graph G= (V, E) with edge weights given in the graph (whatever they are). In addition, a minimum spanning tree T= (V, E′) of this graph has also been given to you. Now, say we need to increase the weight of one particular edge e. Does the MST change? If so, show how to compute the new MST in linear time. You should consider two cases: 1). when e∈E′and...

  • Math 103 Homework 3 Paperp Name (printed): Problem 1 In a certain city there is a...

    Math 103 Homework 3 Paperp Name (printed): Problem 1 In a certain city there is a river ruuning through it. There are three islands in the river, and bridges connecting the banks and the islands, as shown below North Banle A South Bank Draw a graph representation of the situation: Answer the following questions: Does it have an Euler circuit? If not, why not? Does it have an Euler path? If not, why not? If you answered ves on any...

  • Problem #1 Let a "path" on a weighted graph G = (V,E,W) be defined as a...

    Problem #1 Let a "path" on a weighted graph G = (V,E,W) be defined as a sequence of distinct vertices V-(vi,v2, ,%)-V connected by a sequence of edges {(vi, t), (Ug, ta), , (4-1,Un)) : We say that (V, E) is a path from tovn. Sketch a graph with 10 vertices and a path consisting of 5 vertices and four edges. Formulate a binary integer program that could be used to find the path of least total weight from one...

  • Input: a directed grid graph G, a set of target points S, and an integer k...

    Input: a directed grid graph G, a set of target points S, and an integer k Output: true if there is a path through G that visits all points in S using at most k left turns A grid graph is a graph where the vertices are at integer coordinates from 0,0 to n,n. (So 0,0,  0,1,  0,2,  ...0,n,  1,0,  etc.) Also, all edges are between vertices at distance 1. (So 00->01, 00->10, but not 00 to any other vertex....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT