When solving algorithmic question, we should consider each detail of the question as each detail and give us a vital hint. Here the detail is : "The Graph has no odd cycles " which means that the Graph is a Bipartite Graph. And all bipartite graph with more than one vertex can be colored using two colors only. Hence, this condition guarantees that the answer will surely exist.
What is a Bipartite Graph? The vertex set of Graph
can be divided/partitioned into two parts
and
such that there is no edges among vertices in
and no edges among vertices in
. If any edge is present it should be between
and
. A bipartite graph looks like the following :
The two partitions are
and
. You can easy color the partition V1 with red color and V2 with
the white color.
The actual coloring requires us to traverse the Graph can can be done with a Breadth First Traversal of the Graph.
The below algorithm accomplishes this :
1.
Initialize an empty Queue Q.
2. Mark a source vertex as RED and insert into Q.
3. Pop vertex v from Q.
4. Find all unmarked neighbor of v and mark them a different color
from v. (This means that if v is RED then mark neighbors as WHITE
and vice-versa)
5. Insert all the neighbors in Q.
6. Repeat Steps 3,4,5 till the Q becomes empty.
7. If any vertex remains unmarked then make it source and start
from step 2.
Note that the Graph may be disconnected, then step 7 takes care of the Disconnected Graph case.
Time Complexity : This is simply the Breadth
First Search with additional constant time steps to mark the vertex
and can be done in
time. This is because all Vertex will be pushed in Q only once.
Also, to check the neighbors we have to look at the E edges. The
overall complexity would be
.
Proof : We know that a graph is Bipartite if and only if it has no odd cycles. A breadth First Traversal of the Bipartite Graph will lead to the bi-coloring because for every edge traverse we would be jumping from the partition V1 to V2 with one partition being colored as Red and the other as White. This preserves the "no neighbor with the same color" property. Hence, the algorithm is correct.
Given a graph G with no odd cycles, we want to color the vertices with two...
Suppose you are given an undirected graph G. Find a pair of vertices (u, v) in G with the largest number of common adjacent vertices (neighbors). Give pseudocode for this algorithm and show the worst-case running time.
Let G be a graph in which there is a cycle C odd length that has vertices on all of the other odd cycles. Prove that the chromatic number of G is less than or equal to 5.
A 2-coloring of an undirected graph with n vertices and m edges is the assignment of one of two colors (say, red or green) to each vertex of the graph, so that no two adjacent nodes have the same color. So, if there is an edge (u,v) in the graph, either node u is red and v is green or vice versa. Give an O(n + m) time algorithm (pseudocode!) to 2-colour a graph or determine that no such coloring...
3. Use Kuratowski's theorem to determine whether the given graph is planar. Construct the dual graph for the map shown. Then, find the number of colors needed to color the map so that no two adjacent regions have the same color. 4. a) b) CCE 5. Show that a simple graph that has a circuit with an odd number of vertices in it cannot be colored using two colors.
3. Use Kuratowski's theorem to determine whether the given graph is...
Give an efficient algorithm that takes a directed graph G = (V, E) and two vertices u, v E V, and determines if there are at least two edge-disjoint paths in G from u to v. i.e., your algorithm should determine whether there are at least two paths from u to v in G that have no edges in common. Argue your algorithm's correctness and analyze its time complexity.
Problem 1: Given a graph G (V,E) a subset U S V of nodes is called a node cover if each edge in E is adjacent to at least one node in U. Given a graph, we do not know how to find the minimum node cover in an efficient manner. But if we restriet G to be a tree, then it is possible. Give a greedy algorithm that finds the minimum node cover for a tree. Analyze its correctness...
Triangle is a complete graph on 3 vertices (see below) You are given a graph G, and you need to calculate the number of triangles contained in G. Develop an efficient (better than cubic) algorithm to solve this problem. What is its running time? Explain your answer
Triangle is a complete graph on 3 vertices (see below) You are given a graph G, and you need to calculate the number of triangles contained in G. Develop an efficient (better than...
Given a directed graph G, give an algorithm that tests if G is acyclic. Analyze running time.
B-1 Graph coloring Given an undirected graph G (V. E), a k-coloring of G is a function c : V → {0, 1, . . . ,k-1} such that c(u)≠c(v) for every edge (u, v) ∈ E. In other words, the numbers 0.1,... k-1 represent the k colors, and adjacent vertices different colors. must havec. Let d be the maximum degree of any vertex in a graph G. Prove that we can color G with d +1 colors.
2. For a given graph G, we say that H is a clique if H is a complete subgraph of Design an algorithm such that if given a graph G and an integer k as input, determines whether or not G has a clique with k vertices in polynomial time. (Hint: Try to first find a polynomial time algorithm for a different problem and reduce the clique problem to that problem).
2. For a given graph G, we say that...