Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Here's a proposal for how to find the length of the shortest cycle in an undirected graph with unit edge lengths. When a back edge, say (v,w), is encountered during a depth-first search, it forms a cycle with the tree edges from wtov. The length of the cyclelevel[v]-level[w+1] is where the level of a vertex is its distance in the DFS tree from the root vertex. This suggests the following algorithm:

• Do a depth-first search, keeping track of the level of each vertex.

• Each time a back edge is encountered, compute the cycle length and save it if it is smaller than the shortest one previously seen. Show that this strategy does not always work by providing a counterexample as well as a brief (one or two sentence) explanation.

Short Answer

Expert verified

The given strategy fails when the shortest cycle consists of more than the one back edge.

Step by step solution

01

Define graphs

A graph consists of nodes and edges. These nodes are also known as vertices. In undirected graphs, the nodes are connected by bidirectional edges. On the other hand, a directed graph is one in which all of the edges point in some particular direction.

02

Determine a counter example where the given strategy fails

The node's level is equal to its distance of the node from the root node. If there are more than one back edges in the shortest cycle, the given strategy to find the shortest cycle in an undirected graph fails. Consider the following graph:

The above diagram illustrates an undirected graph. In this undirected graph, the shortest cycle would be 1451. But the given algorithm would detect 12341.

Hence, it can be concluded that the given strategy fails when the shortest cycle consists of more than one back edge.

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 Vaia!

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 with (possibly negative) weighted edges, in which the shortest path between any two vertices is guaranteed to have at most edges. Give an algorithm that finds the shortest path between two vertices u and v in O(KE)time.

Generalized shortest-paths problem.In Internet routing, there are delays on lines but also, more significantly, delays at routers. This motivates a generalized shortest-paths problem.

Suppose that in addition to having edge lengths {Ie:eE} ,a graph also has vertex costs {cV:vV} . Now define the cost of a path to be the sum of its edge lengths, plusthe costs ofall vertices on the path (including the endpoints). Give an efficient algorithm for the followingproblem.

Input:A directed graph G={V,E} positive edge lengths Ie and positive vertex costs cv; a starting vertex sv.

Output:An array cost[.] such that for every vertex u,costu, is the least cost of any path from s to u (i.e., the cost of the cheapest path), under the defnition above.

Notice that cost[s]=c.

In cases where there are several different shortest paths between two nodes (and edges have varying length),the most convenient of these paths is often the one with fewest edges. Forinstance, if nodes represent cities and edge lengths represent costs of flying between cities, theremight be many ways to get from cityto city t which all have the same cost. The mostconvenientof these alternatives is the one which involves the fewest stopovers. Accordingly, for a specific starting node S , define

bestu=minimum number of edges in a shortest path from S to u .

In the example below, thebestvalues for nodes S,A,B,C,D,E,Fare 0,1,1,1,2,2,3, respectively.

Give an efficient algorithm for the following problem.

Input:Graph G=V,E; positive edge lengths le; starting node sV.

Output: The values of bestu should be set for all nodesuV

Suppose we want to run Dijkstra’s algorithm on a graph whose edge weights are integers in the range 0,1,........,W, where Wis a relatively small number.
(a) Show how Dijkstra’s algorithm can be made to run in time

O(W|V|+|E|)

(b) Show an alternative implementation that takes time just .

O((|V|+|E|)logW)

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.

Sign-up for free