/*! 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 Design a linear-time algorithm w... [FREE SOLUTION] | 91影视

91影视

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 鈥榮 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 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

Infinite paths.Let G=(V,E) be a directed graph with a designated 鈥渟tart vertex鈥 sV,asetVGV, a set of 鈥済ood鈥 vertices, and a set VBV of 鈥渂ad鈥 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.

Rewrite the explore procedure (Figure 3.3) so that it is non-recursive (that is, explicitly use a stack). The calls to pre visit and post visit should be positioned so that they have the same effect as in the recursive procedure.

Give a linear-time algorithm for the following task.
Input: A directed acyclic graph G

Does G contain a directed path that touches every vertex exactly once?

You are given tree T=(V,E) along with a designated root node rV. The parent of any node Vr, denoted p(V), is defined to be the node adjacent to v in the path from r to v . By convention, p(r)=r. For k>1, define pk(v)pk-1(pv)andp1(v)=p(v)(so pk(v)is the k th ancestor of v ). Each vertex v of the tree has an associated non-negative integer label l(v). Given a linear-time algorithm to update the labels of all the vertices T according to the following rule: lnew(v)=l(plvv).

A bipartite graph is a graph G=(V,E)whose vertices can be partitioned into two sets (V=V1V2andV1V2=) such that there are no edges between vertices in the same set (for instance, if , then there is no edge between and ).

(a) Give a linear-time algorithm to determine whether an undirected graph is bipartite.

(b) There are many other ways to formulate this property. For instance, an undirected graph is bipartite if and only if it can be colored with just two colors. Prove the following formulation:

an undirected graph is bipartite if and only if it contains no cycles of odd length.

(c) At most how many colors are needed to color in an undirected graph with exactly one odd length?

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.