/*! 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} 21E Give a linear-time algorithm to ... [FREE SOLUTION] | 91影视

91影视

Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve this problem under the assumption that the graph is strongly connected.)

Short Answer

Expert verified

A linear-time algorithm to find an odd-length cycle in a directed graph is proved.

Step by step solution

01

Step 1: Explain odd length cycle in a graph

An odd-length cycle in a directed graph and the graph is strongly connected if and only if one or more of its strongly connected components is non bipartite. This is because if the graph is non bipartite then only it containsodd-length cycle in a directed graph.

02

Step 2: Define an algorithm to find an odd-length cycle in a directed graph.

Algorithm to find out an odd-length cycle in a directed graph with the assumption that the graph is strongly connected this is done by BFS.

Abipartite graph is a graph whose vertices areand.hereandare bipartite to each other it means all nodes of graphis connected itself or is not connected with any other node in a same graph as well as with graph.

The vertices ofare connected by vertices ofbut the nodes of these graph are not connected with any node of its own graph is known as bipartite graph.

It is only possible if the graph coloring is there and it is also used for finding odd length cycle in a directed graph.

If any graph has odd length cycle, then it is not bipartite. An example used here is if it is proved that the graph is bipartite then the graph does not contain any odd length of cycle.

03

Determine the breadth first search.

A linear-time algorithm to determine an odd-length cycle in a directed graph with the assumption that the graph is strongly connected this is done by BFS. or also finding out whether a directed graph is bipartite or not.

Algorithm to determine the given graph isbipartite or not in a directed graph by breadth first search (BFS) is as follows,

1). Consider graph which contain two sets of graphs named asand.

2). Take Red color node as a source vertex and put this vertex in a set. after that color all the vertices blue which are directly connected to the source vertex and put these vertices to another set named.

3). After that the blue vertex is connected with other node, color it red and put into the set ofgraph.

4). The vertices of blue color and the vertices are in red color are not directly connected to each other. It means take all vertices of graphis in red color and all vertices of graphis in blue color.

5).Like that, assign red and blue color to all vertices and it satisfies all the constraints of way coloring problem in which .

Hence, it is clear that if any graph has odd length cycle, then it is not bipartite. And it is also proved that if a graph is bipartite then it always contains even number of cycles are only by using the graph coloring property.

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

On page 102, we defined the binary relation 鈥渃onnected鈥 on the set of vertices of a directedgraph. Show that this is an equivalence relation(see Exercise 3.29), and conclude that it partitions the vertices into disjoint strongly connected components.

Question:Undirected vs. directed connectivity.

(a) Prove that in any connected undirected graph G =(V , E)there is a vertexvV whose removal leaves G connected. (Hint: Consider the DFS search tree for G.)

(b) Give an example of a strongly connected directed graph G(V ,E)such that, for everyvV, removing v from G leaves a directed graph that is not strongly connected.

(c) In an undirected graph with two connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components 0 such that no addition of one edge can make the graph strongly connected.

In an undirected graph, the degreed(u) of a vertex u is the number of neighbours u is the number of neighbors u has, or equivalently, the number of edges incident upon it. In a directed graph, we distinguish between the indegreedin(u), which is the number of edges into u, and the outdegreedout(u), the number of the edges leaving u.

(a) Show that in an undirected graph, role="math" localid="1658908755010" uevd(u)=2|E|

(b) Use part (a) to show that in an undirected graph, there must be an even number of vertices whose degree is odd.

(c) Does a similar statement hold for the number of vertices with odd indegree in a directed graph?

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.

Pouring water.

We have three containers whose sizes are 10 pints, 7 pints, and 4 pints, respectively. The 7-pint and 4-pint containers start out full of water, but the 10-pint container is initially empty. We are allowed one type of operation: pouring the contents of one container into another, stopping only when the source container is empty or the destination container is full. We want to know if there is a sequence of pouring鈥檚 that leaves exactly 2 pints in the 7- or 4-pint container.

(a) Model this as a graph problem: give a precise definition of the graph involved and state the specific question about this graph that needs to be answered.

(b) What algorithm should be applied to solve the problem?

(c) Find the answer by applying the algorithm.

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.