954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem in checking a matrix if it's transitive or not

Hello,

I have a file and this it how it looks like:

6
{a, b, c, d, e, f}
1 1 1 0 0 0
0 1 1 0 0 0
0 0 1 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
1 1 1 1 1 1

6 is the number of elements in the set and {a, b, c, d, e, f} is the list of set members and the matrix is the relation matrix.


I read the file into 2-D array with no problems but I want to check if the matrix is transitive or not. This is how to check :

If Mij=Mjk = Mik

I implemented a method to check it but the output is always transitive !

public static boolean CheckTransitive(int array[][])
   	{

		boolean check=true;

		while(check==true)
		{

		    	for(int i=0;i<array.length;i++)
		    		{
		    		for( int j =0;j<array[i].length;j++)
		    			{
		    			for( int k =0;k<array[j].length;k++)
		    				{

		    				if (array[i][j]==array[j][k]){
						  if(array[i][j]!=array[i][k]){
					 	             check=false;
					 		     break;

								}

		    				}

    					}break;
   				}break;

		    	}break;
  	 }
  	 if(check==true){
  	 	return true;

  	 }else{
  	 	return false;
  	 }


	}


Could any one please tell me why the output is always transitive (true) ! and where is exactly the wrong in my code ?

Thanks in advance :)

matrixcool
Newbie Poster
13 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

try to trace the program on the loop containing k as the counter
the value of check must be still equal to true cause after that loop you break the statement before that and then you break the statement before that...until you break the while loop

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: