Design a linear-time algorithm which, given an undirected graph G and a particular edge ein it, determines whetherGhas a cycle containing.

Short Answer

Expert verified

An undirected graphG and edgeein it with verticesv , and for detecting a cycle in an undirected graph depth first search algorithm is used.

If back edge present during depth first search than it means cycle is present in the graph.

Step by step solution

01

Depth First Search.  

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 downward direction one by one.

A graph contains various edges: they areas follows:

tree edge, forward edge and back edge.

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.

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)whereuis descendant and it is not part of depth first search is called forward edge.

Back edge: the edge(u,v) whereu is ancestor and it is not part of depth first search is called forward edge.

In the given question, applieddepth-first search where the order of traverse is ABEGFDC.

02

Step 2:  Applying depth first search.

A linear-time algorithm which, given an undirected graphG and a particular edge e in it, and graphG has a cycle containinge .

Let an undirected graph Gwhich contain edges eand verticesv here the number of edges are nine and the vertices are seven. Then start visiting the nodes one by one by depth first search.

Let vertexA is the source vertex and two is the next node by depth first search and It traverses downwards and uses the stack as a data structure through this it traverses all vertices in the downward direction one by one. andIf back edge present during depth first search than it means cycle is present in the graph. Depth first search ‘s main application is to find out the cycle in the graph.

Apply depth first search and It traverses downwards direction push and pop operation are taking place in the stack. By using stack recursion, the depth first search tree is formed and traverse through the top vertex called as source vertex to reached in the last vertex as known as the end vertex. And the order after applying the depth first search in the graph then the order of traverse is ABEGFDC.

03

Step3: Determine whether G has a cycle containing e.                                

Fig: Depth first search tree contains cycle.

Here depth first search takes linear-time. The order of traverse isABEGFDC .

And this graph Ghas a cycle present in it containing edge e. And back edge present during depth first search than it means cycle is present in the graph. Hence the given statement is proved.

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

Run the strongly connected components algorithm on the following directed graphs G. When doing DFS on GR: whenever there is a choice of vertices to explore, always pick the one that is alphabetically first.

In each case answer the following questions.

(a) In what order are the strongly connected components (SCCs) found?

(b) Which are source SCCs and which are sink SCCs?

(c) Draw the “metagraph” (each meta-node is an SCC of G).

(d) What is the minimum number of edges you must add to this graph to make it strongly connected

The chapter suggests an alternative algorithm for linearization (topological sorting), which repeatedly removes source nodes from the graph (page 101). Show that this algorithm can be implemented in linear time.

Infinite paths.Let G=(V,E) be a directed graph with a designated “start vertex” sV,asetVGV, a set of “good” vertices, and a set VBV of “bad” vertices. An infinite trace of is an infinite sequence of vertices viV such that (1)v0=s, and (2) for all i0, (vi,vi+1)E. That is, p is an infinite path in G starting at vertex s. Since the setV of vertices is finite, every infinite trace of Gmust visit some vertices infinitely often.

  1. If p is an infinite trace, let Inf(p)V be the set of vertices that occur infinitely often in p. Show that Inf(p) is a subset of a strongly connected component of G.
  2. Describe an algorithm that determines if role="math" G has an infinite trace.
  3. Describe an algorithm that determines if G has an infinite trace that visits some good vertex in VG infinitely often.
  4. Describe an algorithm that determines if role="math" localid="1659627728759" G has an infinite trace that visits some good vertex in VG infinitely often, but visits no bad vertex in VB infinitely often.

Two paths in a graph are called edge-disjointif they have no edges in common. Show that in any undirected graph, it is possible to pair up the vertices of odd degree and find paths between each such pair so that all these paths are edge-disjoint.

Perform depth-first search on each of the following graphs; whenever there’s a choice of vertices, pick the one that is alphabetically first. Classify each edge as a tree edge, forward edge, back edge, or cross edge, and give the pre and post number of each vertex.

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