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

The reverse of a directed graph G = (V,E) is another directed graphGR=(V,ER) on the same vertex set, but with all edges reversed that is,ER={(v,u):(u,v)E} . Give a linear-time algorithm for computing the reverse of a graph in adjacency list format.

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

In the 2SAT problem, you are given a set of clauses, where each clause is the disjunction (OR) of two literals (a literal is a Boolean variable of or the negation of a Boolean variable). You are looking for a way to assign a valuetrueorfalseto each of the variables so that all clauses are satisfied- that is, there is at least one true literal in each clause. For example, here’s an instance of 2SAT:

x1x2¯x1¯x3¯x1x2x3¯x4x1¯x4

This instance has a satisfying assignment: set x1,x2,x3, and x4 totrue, false, false,andtrue,respectively.

  1. Are there other satisfying truth assignments of this 2SAT formula? If so, find them all.
  2. Give an instance of 2SAT with four variables, and with no satisfying assignment.

The purpose of this problem is to lead you to a way of solving 2SAT efficiently by reducing it to the problem of finding the strongly connected components of a directed graph. Given an instance l of 2SAT with n variables and m clauses, construct a directed graph GI=V,E as follows.

  • GIhas 2nnodes, one for each variable and its negation.
  • GIhas 2m edges: for each clause αβof l (where α,βare literals), G1has an edge from the negation of α to β, and one from the negation ofβ to α.

Note that the clause αβis equivalent to either of the implications α¯β or β¯α. In this sense, data-custom-editor="chemistry" GI records all implications in l .

(C). Carry out this construction for the instance of 2SAT given above, and for the instance you constructed in (b).

(d). Show that if GI has a strongly connected component containing both x and X¯ for some variable x , then l has no satisfying assignment.

(e). Now show the converse of (d): namely, that if none of GI’s strongly connected components contain both a literal and its negation, then the instance l must be satisfiable.(Hint: Assign values to the variables as follows: repeatedly pick a sink strongly connected component of GI. Assign valuetrueto all literals in the sink, assignfalseto their negations, and delete all of these. Show that this ends up discovering a satisfying assignment.)

(f). Conclude that there is a linear-time algorithm for solving 2SAT.

Either prove or give a counterexample: if {u,v}is an edge in an undirected graph, and during depth-first search (u)<post (v), then vis an ancestor of uin the DFS tree.

Biconnected componentsLet G=(V,E) be an undirected graph. For any two edgese,e'E,, we’ll saye:e'if eithere=e'or there is a (simple) cycle containing both e and e'.

a. Show that : is an equivalence relation (recall Exercise 3.29) on the edges.

The equivalence classes into which this relation partitions the edges are called the biconnected components of G . A bridge is an edge which is in a biconnected component all by itself.

A separating vertexis a vertex whose removal disconnects the graph.

b. Partition the edges of the graph below into biconnected components, and identify the bridges and separating vertices.

Not only do biconnected components partition the edges of the graph, they almost partition the vertices in the following sense.

c. Associate with each biconnected component all the vertices that are endpoints of its edges. Show that the vertices corresponding to two different biconnected components are either disjoint or intersect in a single separating vertex.

d. Collapse each biconnected component into a single meta-node, and retain individual nodes for each separating vertex. (So there are edges between each component node and its separating vertices.) Show that the resulting graph is a tree.

DFS can be used to identify the biconnected components, bridges, and separating vertices of a graph in linear time.

e. Show that the root of the DFS tree is a separating vertex if and only if it has more than one child in the tree.

f. Show that a non-root vertex v of the DFS tree is a separating vertex if and only if it has a child v' none of whose descendants (including itself) has a back edge to a proper ancestor of v .

g. For each vertex u define:

Iowu=minpreuprew

Where (v,w) is a back edge for some descendant v of u.

(h) Show how to compute all separating vertices, bridges, and biconnected components of a graph in linear time.

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