/*! 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} Q7E You are given a directed graph G... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

You are given a directed graph G(V,E)with (possibly negative) weighted edges, along with a specific node s∈Vand a tree T=(V,E'),E'⊂E. Give an algorithm that checks whether T is a shortest-path tree for G with starting point s . Your algorithm should run in linear time.

Short Answer

Expert verified

The algorithm to check whether T is a shortest-path tree for G with starting point s is explained, which runs in a linear time.

Step by step solution

01

Algorithm used for negative weighted directed graph.

Bellman Ford algorithmis an application of single source shortest path, which is used forfinding the shortest distance from one vertex to other vertices of a weighted directed graph.

It is almost similar to Dijkstra's algorithm but Dijkstra's algorithm is works only for the graph with a positive weight and Bellman Ford algorithm is works with graphs in which edges have negative weights in its graph.

02

Design the Algorithm .T=(V,E'),E'⊂E

Bellman-Ford algorithm applies to the graph for finding the single source’s shortest path.A directed graph with positive and negative edge weight, and returns the length of the shortest cycle in the graph and the graph is acyclic, which takes linear time. So, here the vertex A is the source vertex. now take an array as a data structure to evaluate single source shortest path between the source and the destination.

From A the distance of A is zero and take the distance of vertex A from each and every vertex is infinity. Now take A as the first vertex and evaluate the weight towards each vertex and draw a directed positive and negative weighted graph:

Choose the next vertex from the vertices which have minimum weight and select that node as the second vertex. Then again evaluate the distance of it from every vertex and as get the minimum weight of the node and consider it as the main node. Through this the series of the vertex arises.

Here the vertex A is the source vertex. now take a minheap as a data structure for evaluate single source shortest path between the source and the destination.

From A the distance of A is zero and take the distance of vertex A from each and every vertex is infinity.

All vertices will be released many times in the Bellman-Ford algorithm.

Select every vertex one by one and put it into the array as a data structure one by one as shown in the figure.

Hence, the shortest distance from vertex A to vertex D is evaluated in linear time

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

Shortest path algorithms can be applied in currency trading. Let c1,c2,cn be various currencies; for instance, c1might be dollars, c2pounds, and c3 lire.

For any two currencies ci and cj , there is an exchange rate τi,j; this means that you can purchase τi,j units of currency cj in exchange for one unit of cj. These exchange rates satisfy the condition that rij.rji<1 so that if you start with a unit of currency cj, change it into currency and then convert back to currency localid="1658917254028" ci, you end up with less than one unit of currency ci (the difference is the cost of the transaction).

a. Give an efficient algorithm for the following problem: Given a set of exchange rates rij , and two currencies s and t , find the most advantageous sequence of currency exchanges for converting currency into currency . Toward this goal, you should represent the currencies and rates by a graph whose edge lengths are real numbers.

The exchange rates are updated frequently, rejecting the demand and supply of the various currencies. Occasionally the exchange rates satisfy the following property: there is a sequence of currencies ci1,ci2,.......ciksuch that ri1,ri2.i3,.........ri(k-1),ik,rik+1>1. This means that by starting with a unit of currency ci1and then successively converting it to currencies ci1,ci2.......cik, and finally back to ci1, you would end up with more than one unit of currency ci1 . Such anomalies Last only a fraction of a minute on the currency exchange, but they provide an opportunity for risk-free profits.

b. Give an efficientalgorithm for detecting the presence of such an anomaly. Use the graph representation you found above.

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.

Just like the previous problem, but this time with the Bellman-Ford algorithm.

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.

Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges {u,prepu}(forall∈v)form a 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.