Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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 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 police department in the city of Computopia has made all streets one-way. The mayor contends that there is still a way to drive legally from any intersection in the city to any other intersection, but the opposition is not convinced. A computer program is needed to determine whether the mayor is right. However, the city elections are coming up soon, and there is just enough time to run a linear-time algorithm.

a) Formulate this problem graph-theoretically, and explain why it can indeed be solved in linear time.

(b) Suppose it now turns out that the mayorโ€™s original claim is false. She next claims something weaker: if you start driving from town hall, navigating one-way streets, then no matter where you reach, there is always a way to drive legally back to the town hall. Formulate this weaker property as a graph-theoretic problem, and carefully show how it too can be checked in linear time.

Infinite paths.Let G=(V,E) be a directed graph with a designated โ€œstart vertexโ€ sโˆˆV,asetVGโІV, a set of โ€œgoodโ€ vertices, and a set VBโІV of โ€œbadโ€ vertices. An infinite trace of is an infinite sequence of vertices viโˆˆV such that (1)v0=s, and (2) for all iโ‰ฅ0, (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.

Let S be a finite set. A binary relation on S is simply a collection R of ordered pairs(x,y)โˆˆSร—S. . For instance, S might be a set of people, and each such pair (x,y)โˆˆR might mean โ€œ x knows y โ€.

An equivalence relationis a binary relation which satisfies three properties:

  • Reflexivity: localid="1659006645990" (x,y)โˆˆR for all XโˆˆS
  • Symmetry: If (x,y)โˆˆR then (y,x)โˆˆR
  • Transitivity: if (x,y)โˆˆR and (y,z)โˆˆR then localid="1659006784500" (x,Z)โˆˆR

For instance, the binary relation โ€œhas the same birthday asโ€ is an equivalence relation, whereas โ€œis the father ofโ€ is not, since it violates all three properties.

Show that an equivalence relation partition set S into disjoint groups S1,S2,โ€ฆ,Sk (in other words, S=S1โˆชS2โˆชโ€ฆโˆชSkandSiโˆฉSj=ฯ•foralliโ‰ j ) such that:

  • Any two members of a group are related, that is, (x,y)โˆˆR for any localid="1659006702579" (x,y)โˆˆSi, for any i .
  • Members of different groups are not related, that is, for all iโ‰ j, for all localid="1659006762355" xโˆˆSi andyโˆˆSi, we have (x,Z)โˆˆR.

(Hint: Represent an equivalence relation by an undirected graph.)

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.

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?

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