0% found this document useful (0 votes)
10 views4 pages

PROJECT Graph Colouring With GUI

The document discusses graph coloring using a greedy algorithm, detailing the steps for assigning colors to vertices such that no two adjacent vertices share the same color. It outlines the time complexity for adding nodes or edges as O(1) and the overall space complexity for the graph representation as O(V+E). An example illustrates the coloring process for a graph with four vertices, demonstrating the algorithm's efficiency.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

PROJECT Graph Colouring With GUI

The document discusses graph coloring using a greedy algorithm, detailing the steps for assigning colors to vertices such that no two adjacent vertices share the same color. It outlines the time complexity for adding nodes or edges as O(1) and the overall space complexity for the graph representation as O(V+E). An example illustrates the coloring process for a graph with four vertices, demonstrating the algorithm's efficiency.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: K V MANOJ KUMAR

Reg No: 23MIP10113

GRAPH COLOURING WITH GUI


CODE IMPLEMENTATION:
OUTPUT:

Time Complexity:
The time complexity for adding a node or an edge in a graph is O(1). This means that regardless of
the size of the graph (i.e., the number of nodes or edges), the time taken to perform these
operations remains constant. This efficiency is due to the fixed amount of work required to update
the data structure that represents the graph, such as an adjacency list or adjacency matrix. For
instance, when adding a node, you simply need to create a new entry in your data structure.
Similarly, adding an edge typically involves updating two entries (for both nodes) to reflect their
connection.

Space Complexity:
The space complexity for adding a node or edge is also O(1) for each operation, as you are only
adding a single node or a single edge to the graph's representation. However, the overall space used
by the graph increases as you add more nodes and edges. If the graph has VVV vertices and EEE
edges, the total space complexity for the graph's representation might be O(V+E), accounting for the
storage of all nodes and edges collectively.

GRAPH COLOURING ALGORITHM (GREEEDY APPROACH):

The graph coloring problem involves assigning colors to the vertices of a graph such that no two
adjacent vertices share the same color. The goal is to use the minimum number of colors while
ensuring that adjacent vertices have different colors.

Steps of the Greedy Algorithm:

1. Initialization:

o Start with an empty coloring (no vertices colored).

o List all the vertices of the graph.

2. Assign Colors:

o Iterate through each vertex in the graph.

o For each vertex, consider the colors already assigned to its adjacent vertices
(neighbors).

o Select the smallest available color that is not used by any of its neighbors.

o Assign this color to the vertex.

3. Repeat:

o Repeat the above step for all vertices in the graph.

Example:

Let's go through a simple example with a graph of 4 vertices (A, B, C, D) and the following edges:

 A-B, A-C, B-C, B-D, C-D

Step-by-Step Coloring:

1. Vertex A: Assign the first color (let's say Color 1) as no neighbors are colored yet.

o A: Color 1
2. Vertex B: Adjacent to A (Color 1), so assign the next available color (Color 2).

o A: Color 1, B: Color 2

3. Vertex C: Adjacent to both A (Color 1) and B (Color 2), so assign the next available color
(Color 3).

o A: Color 1, B: Color 2, C: Color 3

4. Vertex D: Adjacent to B (Color 2) and C (Color 3), so assign the next available color (Color 1).

o A: Color 1, B: Color 2, C: Color 3, D: Color 1

In this example, we used 3 different colors to color the graph.

Time and Space Complexity:

 Time Complexity: O(V+E)

o The algorithm processes each vertex once and checks all its adjacent vertices
(neighbors) to assign the smallest available color.

o VV represents the number of vertices.

o EE represents the number of edges.

 Space Complexity: O(V+E)

o The graph is represented using an adjacency list, which takes O(V+E) space.

o An additional array or dictionary is used to store the color of each vertex, which
takes O(V) space.

You might also like