/*! 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} Q11E Give an algorithm that takes as ... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

Give an algorithm that takes as input a directed graph with positive edge lengths, and returns the length of the shortest cycle in the graph (if the graph is acyclic, it should say so). Your algorithm should take time at most O|V3|.

Short Answer

Expert verified

A directed graph with positive edge lengths, and returns the length of the shortest cycle in the graph take time at mostOV3 it proved by the Dijkstra’s algorithm, which is an application of a single source shortest path.

Step by step solution

01

Define the concept of the algorithm used for the directed graph.

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

Dijkstra’s algorithm also known asthe SPF algorithm and is an algorithm for finding the shortest paths between thevertices 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.

02

Time complexity of Dijkstra’s algorithm

Time complexity:

TC=V+VIogV+E+EIogVTC=VIogV+ElogVTC=OV+ElogV

For finding the shortest path adjacent list and min heap may be used.

The time complexity isTC=OV+ElogV.

And, if the graph is acyclic then the complexity is:OV3.

03

Design the Algorithm

Dijkstra algorithm applies on the graph for finding the single source shortest path.

A directed graph with positive edge lengths, and returns the length of the shortest cycle in the graph and the graph is acyclic, which takes time at mostOV3.

So, here the vertex A is the source vertex. now take a minheap as a data structure to evaluate a single source’s 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 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 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 evaluatinga single source’s 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.

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

Hence, the shortest distance from the vertex A to vertex D is 13 .

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

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.

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.

Squares.Design and analyse an algorithm that takes as input an undirected graph G(V,E) and determines whether graph contains a simple cycle (that is, a cycle which doesn’t intersect itself) of length four. Its running time should be at mostO(V3) time.

You may assume that the input graph is represented either as an adjacency matrix or with adjacency lists, whichever makes your algorithm simpler.

Consider a directed graph in which the only negative edges are those that leaves; all other edges are positive. Can Dijkstra's algorithm, started at s, fail on such a graph? Prove your answer.

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.

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.