Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Addition of Graph Coloring Problem in Graphs directory #2617

Closed
Charuhas10 opened this issue Oct 10, 2023 · 2 comments
Closed

[FEATURE] Addition of Graph Coloring Problem in Graphs directory #2617

Charuhas10 opened this issue Oct 10, 2023 · 2 comments
Labels
enhancement New feature or request stale Author has not responded to the comments for over 2 weeks

Comments

@Charuhas10
Copy link

Detailed description

Proposal

Addition of Graph Coloring Problem algorithm under in Graphs directory

Overview

The graph coloring problem asks to assign colors to the vertices of a graph in such a way that no two adjacent vertices share the same color. The objective is often to color the graph with as few colors as possible.

Issue details

The greedy coloring algorithm is a straightforward approach to solve this problem. Here's a basic outline of the greedy algorithm:

  1. Ordering the Vertices: Although not strictly necessary, the algorithm can start by ordering the vertices in some fashion. Different orderings may produce different results. A common ordering is by the degree of the vertices, but the simplest is just the order in which the vertices are given.
  2. Coloring: Start with the first vertex and assign it the first color. Then move to the next vertex.
    For each subsequent vertex, look at its neighbors and determine what colors have already been assigned. Assign the smallest possible color that hasn't been used by its neighbors.

More Details

https://en.wikipedia.org/wiki/Graph_coloring

Context

This change is crucial as it addresses a common problem in graph theory solved using greedy approach, enhancing the repository's comprehensiveness

Possible implementation

Pseudo Code:

Algorithm GreedyGraphColoring(G):
    Input: A graph G with V vertices
    Output: A color assignment for each vertex

    Initialize an array color[] of size V and set all to -1 (indicating uncolored)
    Initialize an array available[] of size V and set all to False (indicating all colors are initially available)
    
    Assign color[0] = 0  // Assign the first color to the first vertex
    
    FOR vertex u from 1 to V-1 DO
        FOR each vertex i from 0 to V-1 DO
            IF there's an edge between u and i AND color[i] is not -1 THEN
                SET available[color[i]] = True
            END IF
        END FOR

        // Find the first available color
        clr = 0
        WHILE clr < V AND available[clr] is True DO
            INCREMENT clr
        END WHILE

        Assign color[u] = clr

        Reset available[] to False for the next iteration
    END FOR

    RETURN color

END Algorithm

Additional information

No response

@Charuhas10 Charuhas10 added the enhancement New feature or request label Oct 10, 2023
harshika0926 added a commit to harshika0926/C-Plus-Plus that referenced this issue Oct 14, 2023
…tory TheAlgorithms#2617

Detailed description
Proposal
Addition of Graph Coloring Problem algorithm under in Graphs directory

Overview
The graph coloring problem asks to assign colors to the vertices of a graph in such a way that no two adjacent vertices share the same color. The objective is often to color the graph with as few colors as possible.

Issue details
The greedy coloring algorithm is a straightforward approach to solve this problem. Here's a basic outline of the greedy algorithm:

Ordering the Vertices: Although not strictly necessary, the algorithm can start by ordering the vertices in some fashion. Different orderings may produce different results. A common ordering is by the degree of the vertices, but the simplest is just the order in which the vertices are given.
Coloring: Start with the first vertex and assign it the first color. Then move to the next vertex.
For each subsequent vertex, look at its neighbors and determine what colors have already been assigned. Assign the smallest possible color that hasn't been used by its neighbors.
More Details
https://en.wikipedia.org/wiki/Graph_coloring

Context
This change is crucial as it addresses a common problem in graph theory solved using greedy approach, enhancing the repository's comprehensiveness

Possible implementation
Pseudo Code:
Algorithm GreedyGraphColoring(G):
    Input: A graph G with V vertices
    Output: A color assignment for each vertex

    Initialize an array color[] of size V and set all to -1 (indicating uncolored)
    Initialize an array available[] of size V and set all to False (indicating all colors are initially available)
    
    Assign color[0] = 0  // Assign the first color to the first vertex
    
    FOR vertex u from 1 to V-1 DO
        FOR each vertex i from 0 to V-1 DO
            IF there's an edge between u and i AND color[i] is not -1 THEN
                SET available[color[i]] = True
            END IF
        END FOR

        // Find the first available color
        clr = 0
        WHILE clr < V AND available[clr] is True DO
            INCREMENT clr
        END WHILE

        Assign color[u] = clr

        Reset available[] to False for the next iteration
    END FOR

    RETURN color

END Algorithm
Copy link
Contributor

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Nov 10, 2023
Copy link
Contributor

Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

No branches or pull requests

1 participant