/*! 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

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

Run the DFS-based topological ordering algorithm on the following graph. Whenever you have a choice of vertices to explore, always pick the one that is alphabetically first.

(a) Indicate the pre and post numbers of the nodes.

(b) What are the sources and sinks of the graph?

(c) What topological ordering is found by the algorithm?

(d) How many topological orderings does this graph have?

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.

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鈥檚 an instance of 2SAT:

x1x2x1x3x1x2x3x4x1x4

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

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.

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.