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?

Short Answer

Expert verified

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

(b) An undirected graph is bipartite if and only if it is colored with just two colors. An undirected graph is bipartite if and only if it contains no cycles of odd length is proved.

(c) At most three colors are needed to color in an undirected graph with exactly one odd length.

Step by step solution

01

Explain Bipartite graph.

Bipartite graph is a graph G whose vertices are and v where 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 ofu are connected by vertices of vbut the nodes of these graph are not connected with any node of its own graph is known as bipartite graph.

A bipartite graph is defined as a graph where each vertex of its own set are never connected with each other. It must be connected by to the vertices of the different set of the graph.

02

Define a linear time algorithm to determine whether an undirected graph is bipartite.

a)

Following is the linear time algorithm to check if an undirected graph is bipartite:

1). Consider graph G which contain two sets of graphs named as u and v .

2). Take red color node as a source vertex and put this vertex in a set u . Then, color all the vertices blue which are directly connected to the source vertex and put these vertices to another set named v .

3). The blue vertex is connected with other node, color it red and put into the set of u graph.

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 graph u is in the Red color and all vertices of graph v is in blue color.

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

Fig 1: Bipartite graph

03

Prove (b)

(b)

An undirected graph is bipartite if and only if it contains no cycles of odd length or if it contains cycle of even length then only it is bipartite graph. In the diagram shown in fig 2 , there are 0,1,2,3,4,5,6 some edges they are 0,1,2,3,4,5,6. If 0 is the source vertex so color it red from 0 the two nodes are connected they are one and three color these both vertex with blue color. Now, look at the vertex 1 and 3 if any edge is connected to 1 and 3 then color it red.

From 1 again two edges are connected: they are 4 and 5 .So color these by blue color and again search the next node is 2 . Check whether it is connected to any red colored node or not, if no then color it red. Apply this method for each vertex and now the remaining vertex is 6 , which is connected by both 4 and 5 . Both 4 and 5 are colored with blue. Then, color the vertex as red. Through this it shows that the undirected graph is bipartite.

Fig:2 Showing undirected bipartite graph.


Fig:3 Showing undirected bipartite graph.

04

Find the number of colors needed in odd length cycle.

c)

The number of colorsneeded to color in an undirected graph with exactly one odd length is three because if the number of vertices is odd then the number of colors required is three. If the number of vertices is even then the number of colors required is two.

Hence, if number of vertices are odd then the number of colors required is three.

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

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?

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.

You are given a directed graph in which each nodeuV, has an associated pricepu which is a positive integer. Define the array cost as follows: for each uV,

cost[u] = price of the cheapest node reachable fromu (includingu itself).

For instance, in the graph below (with prices shown for each vertex), the cost values of the nodes A,B,C,D,E,Fare2,1,4,1,4,5,respectively.

Your goal is to design an algorithm that fills in the entire cost array (i.e., for all vertices).

(a) Give a linear-time algorithm that works for directed acyclic graphs.

(b) Extend this to a linear-time algorithm that works for all directed graphs.

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 XS
  • 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=S1S2SkandSiSj=ϕforallij ) 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 ij, for all localid="1659006762355" xSi andySi, we have (x,Z)R.

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

As in the previous problem, you are given a binary tree T=(V,E) with designated root node. In addition, there is an array x[.]with a value for each node in V Define a new array z[.]as follows: for each uV,

z[u]=the maximum of the x-values associated with u’s descendants.

Give a linear-time algorithm that calculates the entire z-array.

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