/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q13E You are given a set of cities, a... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

You are given a set of cities, along with the pattern of highways between them, in the form of an undirected graph G = (V , E). Each stretch of highway e∈Econnects two cities, and you know its length in miles, le. You want to get from city s to city t. There’s one problem: your car can only hold enough gas to cover L miles. There are gas stations in each city, but not between cities. Therefore, you can only take a route if every one of its edges has length le≤L

(a) Given the limitation on your car’s fuel tank capacity, show how to determine in linear time whether there is a feasible route from sto t.

(b) You are now planning to buy a new car, and you want to know the minimum fuel tank capacity that is needed to travel from s to t. Give anO[(V+E)log|V|]algorithm to determine this.

Short Answer

Expert verified

a). The feasible route or the shortest route from s to t is evaluate by using Dijkstra algorithm and by using depth first search.

b) TC=OV+ElogVtime complexity is performed by the Dijkstra’salgorithm.

Step by step solution

01

Dijkstra’s Algorithm and Depth First search

Perform Dijkstra’s algorithm and Depth First Search.

Dijkstra algorithm is an application of a single source shortest path.

Dijkstra’s algorithm also known as the SPF algorithm and is an algorithm for finding the shortest paths between the vertices in a graph. It returns a search tree for all the paths the given node can take. An acyclic graph is a directed graph that has no cycles. Its operation is performed in the minheap.

Depth First Search (DFS) is an application of graph traversal. It traverses the node downwards and uses the stack as a data structure through this it traverses all vertices in the downward direction one by one.

Some properties ofdepth-first search are as follows:

  1. Using DFT we can verify that the graph is connected or not it means it detects the cycle present in the graph or not.
  2. We can find out the number of connected components by usingdepth-first search.
  3. Here we are using stack as a data structure.

The time complexity of list is OV+E

The time complexity of matrix isOV2

It contains various edge they aretree edge, forward edge, back edge, or cross edge all the edges are explain below:

Tree edge: The graph obtained by traversing while using depth first search is called its tree edge.

Forward edge: the edge {u , v} where u is descendant and it is not part of depth first search is called forward edge.

Back edge: the edge {u , v} where u is ancestor and it is not part of depth first search is called back edge.

02

Determine the feasible route from s to t.

(a)

For finding the feasible route or the shortest route from s to t. Where these are the cities and as given in the question its length in miles, le. And we want to get from city s to city t. There’s one problem that is:

The car can only hold enough gas to cover L miles and there are gas stations in each city, but not between cities. Therefore, in this case first find out the shortest path between these two cities by using Dijkstra algorithm for finding the shortest paths between the vertices in a graph. It returns a search tree for all the paths the given node can take. and after that find out the sequence of cities which consider as a vertex and the distance between them is consider as the edge which may or may not be weighted. And here by using min heap or stack as a data structure the number of vertices as cities are stored in it.

After that apply depth first search It traverses the node downwards and uses the stack as a data structure through this it traverses all vertices in downward direction one by one.

Here the following steps are as follows:

1). Let’s Iteratethroughalltheedgesinthegraph.

2).Checkiftheweightofeveryedgeislessthanthegivenmiles.

3). Ifthereareedgesthatareweightedmorethan,removetheedge.

Otherwise,moveontothenextone.

4). After completing this step nowperformdepth first searchtogetfromcitystocityt

03

Step 3: Dijkstra’salgorithm performs TC=O[V+ElogV] time complexity.

(b)

1). Perform Dijkstra’s algorithm on the graph from s to t by using the returned tree.

2). Find the shortest path from s to t using DFS

while noting the weights of the edges that make up the path.

3). Then return the largest weighted edge in the found shortest path.

Time complexity:

TC=V+VlogV+E+ElogVTC=VlogV+ElogVTC=OV+ElogV

In the given question for finding the shortest path adjacent list and minheap both may use.

The time complexity is TC=O[V+ElogV].

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91Ó°ÊÓ!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges {u,prepu}(forall∈v)form a tree.

Professor F. Lake suggests the following algorithm for finding the shortest path from node to node t in a directed graph with some negative edges: add a large constant to each edge weight so that all the weights become positive, then run Dijkstra’s algorithm starting at node s , and return the shortest path found to node t .

Is this a valid method? Either prove that it works correctly, or give a counterexample.

There is a network of roads G=(V,E) connecting a set of cities . Each road in E has an associated length Ie. There is a proposal to add one new road to this network, and there is a list E' of pairs of cities between which the new road can be built. Each such potential road localid="1659075853079" e'∈E' has an associated length. As a designer for the public works department you are asked to determine the road localid="1659075866764" e'∈E'whose addition to the existing network G would result in the maximum decrease in the driving distance between two fixed cities s and t in the network. Give an efficient algorithm for solving this problem.

Question: Often there are multiple shortest paths between two nodes of a graph. Give a linear-time algorithm for the following task.

Input: Undirected graph G = (V , E )with unit edge lengths; nodesu,v∈V

Output: The number of distinct shortest paths from utov.

Suppose Dijkstra’s algorithm is run on the following graph, starting at node A.

a) Draw a table showing the intermediate distance values of all the nodes at each iteration of the algorithm.

b) Show the final shortest-path tree.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.