Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6828231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:21:32+00:00 2026-05-26T22:21:32+00:00

This is a brute force attempt at the chromatic number of a matrix. It

  • 0

This is a brute force attempt at the chromatic number of a matrix. It seems to work in the sense that it gives me the correct number of colors required but instead of 1,2,3,4 it will display 1,2,3,6. For some reason even if the matrix is possibly successful with fewer colors it will still fail and keep going to the max number. Is there a reason why it continues to fail?

“n” is the max number of colors. “v” is the vertex, and “m” is the number of currently used colors.

pseudo code:
http://i42.tinypic.com/deoc2u.jpg

static int color(){ 
       int i;
       for(i = 1; i <= n; i++)
       {
               if(color(0,i)){
                       return i;}
       }
       return i;
}

    static boolean color(int v, int m) {

    if(v > n-1)
            return true;
    else
    {
            for(int i = 1; i <= m; i++)
            {
                    boolean match = false;
                    q[v] = i;

                            for(int j = 0; j < n; j++)
                            {
                                    if(input[v][j] == 1)                
                                    {
                                            if(q[v] == j+1)
                                                    match = true;
                                    }
                            }

                    if(match == false)
                    {
                            if(color(v+1,m)) 
                                    return true;
                    }
            }
            q[v] = 0;
            return false;
    }

}

sample output:

File Name: file1
Input
6
0 1 1 0 1 1
1 0 1 1 1 1
1 1 0 1 0 1
0 1 1 0 1 1
1 1 0 1 0 1
1 1 1 1 1 0
1 failed
2 failed
3 failed
4 failed
5 failed

Colors:
1 2 3 1 3 6

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:21:32+00:00Added an answer on May 26, 2026 at 10:21 pm

    Gah, I should be asleep! But I can’t count the number of times I’ve put off an assigment to the absolute last possible moment, so I’m feeling sympathetic regarding your deadline.

    It’s not really a “brute-force” approach, since that would actually come down to trying each and every possible node coloring combination and check which ones don’t conflict. Your approach is a heuristic known as greedy coloring. It can find optimal results but can also yield an arbitrarily bad solution. That said, I’ve tried manually going through the sample input you’ve provided (thank you, Microsoft Paint) and following that algorithm the result should indeed be 4 when starting from vertex 0.

    So here’s what I believe might be wrong with your code. In the following extract…

    if(input[v][j] == 1)
    {
        if(q[v] == j+1)
        match = true;
    }
    

    You seem to be comparing the color of the current vertex (which will just be i anyway) to a vertex index, rather than the color of that other vertex. I think you’ll need to alter the inner test to…

    if(i == q[j])
    

    or, if you wish (won’t make a difference)…

    if(q[i] == q[j])
    

    Also, you’re doing a bit too many checks. Vertex 0 can be assigned color 1. Vertex 1 then needs to be checked against vertex 0 if it’s adjacent. Vertex 2 needs to be checked against 0 and 1 if they’re adjacent, and so on. You’re checking against vertices that couldn’t have been assigned a color yet. So don’t limit j to n but limit it to your current vertex v.

    Finally, using a construct like if(match == false) is rather confusing and not necessary. Just use if(!match) instead.

    Hope this helps. If you’re still stuck and I happen to catch the comments in time, I can provide more pointers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a brute force attempt to solve the problem, but it is not
I'm well aware this brute force method is bad and that I should be
This evening I noticed a brute force attack attempt from the same IP address
Is there a less brute-force way to do this? #!/bin/ksh THIS_SCRIPT=$(/usr/bin/readlink -f $(echo $0
I have this grand idea to basically employ some brute force attack to test/verify
I am having some trouble understanding this brute force approach. I am using Perl
In an attempt to write a brute force maze solving C program, I've written
Feeling pretty brain-dead right now. I can, of course, brute-force this, but I feel
This is my lame first attempt. I would like to get a count of
I ahve implemented brute force protection via limitation of failed login counts as here:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.