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

  • SEARCH
  • Home
  • 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 8931721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:10:21+00:00 2026-06-15T09:10:21+00:00

I need to check if a graph is Isomorphic by generating all permutation. I

  • 0

I need to check if a graph is Isomorphic by generating all permutation. I am using this permutation class and now I need to create a graph class that represents the graph as a 2D boolean array. An example would be the user entering in 2 graphs as strings

Ex."0-1 0-2 1-2 1-3 2-3" and "1-3 2-0 0-3 1-2 1-0"

Now in my constrcutor I have to break it up and put it in a 2D boolean array. How would I go about doing that?

The user could also enter in something more complicated like “0-1 1-2 2-3 3-0 0-4 0-11 1-5 1-6 2-7 2-8 3-9 3-10 4-5 6-7 8-9 10-11 4-7 4-8 5-9 5-10 6-9 6-10 7-11 8-11” and “0-1 1-2 2-3 3-0 0-4 0-7 1-4 1-5 2-5 2-6 3-6 3-7 4-8 4-9 5-9 5-10 6-10 6-11 7-8 7-11 8-9 9-10 10-11 11-8”

public class PermutationGenerator
{
    // private data

    private int[] perm;
    private boolean first;

    // constructor

    public PermutationGenerator (int n)
    {
        perm = new int [n];
        first = true;
    }



    public int[] next ()
    {
        int n = perm.length;

        // starting permutation: 0 1 2 3 ... n-1

        if (first)
        {
            first = false;
            for (int i = 0 ; i < n ; i++)
                perm [i] = i;
            return perm;
        }

        // construct the next permutation
        // find largest k so that perm[k] < perm[k+1]; if none, finish

        int i, j, k, l;

        for (k = n - 2 ; k >= 0 && perm [k] >= perm [k + 1] ; k--)
            ;
        if (k < 0)
            return null; // no more

        // find largest l so that perm[k] < perm[l]

        for (l = n - 1 ; l >= 0 && perm [k] >= perm [l] ; l--)
            ;

        // swap perm[k] and perm[l]

        swap (perm, k, l);

        // reverse perm[k+1]...perm[n-1]

        for (i = k + 1, j = n - 1 ; i < j ; i++, j--)
            swap (perm, i, j);

        return perm;
    }


    // swap a[i] and a[j]

    private static void swap (int a[], int i, int j)
    {
        int temp = a [i];
        a [i] = a [j];
        a [j] = temp;
    }
}
  • 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-06-15T09:10:24+00:00Added an answer on June 15, 2026 at 9:10 am

    You have to create a matrix to represent your graph, as shown in this picture:

    enter image description here

    You can start by prompting the user for two nodes that are connected, e.g., 1 and 2. Then you would do

    matrix[1][2] = true;
    

    if you are taking into account the direction, which means that 1 - 2 is different than 2 - 1. Otherwise (a graph non-oriented), you would do

    matrix[1][2] = true;
    matrix[2][1] = true;
    

    Do not forget to initialize the matrix with false, meaning (vertices not connected). Every time you want to check if vertices X and Y are directly connected you just have to access the position (X,Y) of the matrix and check if it is true.

    If your graph is a weighted one, you need to have an additional matrix to hold the weights. Another solution is to have just one matrix of integers where -1 means not connected, and N > 0, means that a given X and Y are connected with a weight N.

    About the user input:

    "0-1 1-2 2-3 3-0 0-4 0-11 1-5 1-6 2-7 2-8 3-9 3-10 4-5 6-7 8-9 10-11 4-7 4-8 5-9 5-10 6-9 6-10 7-11 8-11"

    among others, you can use the Scanner class:

    String input;
    Scanner in = new Scanner(System.in);
    
    // Reads a single line from the console 
    // and stores into name variable
    input = in.nextLine();
    

    Afterwards, you have to parser your input; let us assume a fixed format that will hold the graph vertices, for example:

      String input =  "0-1 0-2 1-2 1-3 2-3";
      int x,y;
    
      for(int i = 0; i < input.length(); i+=4)
      {
           x = Character.getNumericValue(input.charAt(i));   // first vertex 
           y = Character.getNumericValue(input.charAt(i+2)); // second vertice 
           matrix_graph[x][y] = true;
           matrix_graph[y][x] = true; // if the graph is not oriented.
      }   
            
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check for duplicates before saving to the database in the create
I need to check some settings for all users on Windows clients in the
I need to check if my address has any words that matches word in
I'm using Neo4j in a concurrent environment and I have graph that looks like
I need to check if a directed graph is strongly connected , or, in
See this facebook tool to check open graph properties: https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.buysell.com%2Freviews%2Fid%2F2599%2F I don't see any
I need to find out user facebook ID and his/her all public profile using
I have a Rails 3 application using Devise for authentication. Now I need to
I need to write a graph using C++ and I have a little problem.
I need to check for a condition on each page I visit on the

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.