![]() |
VOOZH | about |
Cycle:- cycle is a path of edges and vertices wherein a vertex is reachable from itself. or in other words, it is a Closed walk.
Even Cycle:- In which Even number of vertices is present is known as Even Cycle.
Odd Cycle:- In which Odd number of Vertices is present is known as Odd Cycle.
Given the number of vertices in a Cyclic Graph. The task is to determine the Number of colors required to color the graph so that No two Adjacent vertices have the same color.
Approach:
If the no. of vertices is Even then it is Even Cycle and to color such graph we require 2 colors.
If the no. of vertices is Odd then it is Odd Cycle and to color such graph we require 3 colors.
Examples:
Input : vertices = 3 Output : No. of colors require is: 3 Input : vertices = 4 Output : No. of colors require is: 2
Example 1: Even Cycle: Number of vertices = 4
Color required = 2
Example 2: Odd Cycle: Number of vertices = 5
Color required = 3
Implementation:
No. of colors require is: 3
Complexity Analysis: