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

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.

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)

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,vV

Output: The number of distinct shortest paths from utov.

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|.

Give an O|V|2algorithm for the following task.

Input:An undirected graph G=(V,E); edge lengths Ie>0;an edge eE.

Output:The length of the shortest cycle containing edge e

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