Results 1 to 10 of 10

Thread: cluster series

  1. #1
    ameerulislam is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default cluster series

    I got a problem in hand where I can't find any solution yet.. I don't know how to explain this properly let me begin with some sample input outputs

    Input: {1,1,2,3,3} => Output will be: 2
    Input: {1,1,1,1,1} => Output will be: 1
    Input: {1,2,1,1,1} => Output will be: 1
    Input: {1,1,2,1,1,2,4,4} => Output will be: 3


    So the thing is it will basically out put how many group of 2 or more same consecutive numbers in a series. I hope I'm not speaking gibberish .

    my code is incomplete/wrong.

    Java Code:
    import javax.swing.JOptionPane;
    
    
    public class Cluster {
    
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String a= JOptionPane.showInputDialog("Enter Array size" );
    		int size= Integer.parseInt(a);
    		int [] array = new int[size];
    		
    		for(int i=0; i<size; i++){
    		a= JOptionPane.showInputDialog("Enter array elements" );
    		int n= Integer.parseInt(a);
    		
    		array[i]=n;
    		
    		System.out.print(" "+array[i]);
    
    		}
    		int flag=0;
    		for (int j=0; j<size-1; j++){
    			
    				if (array[j]!=array[j+1]){
    					 flag=flag+1;
    					 if(array[j+1]!=array[j+2]){
    						 
    					 }
    				}
    			
    		} System.out.println(" Clusters "+flag);
    		
    	}
    
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,377
    Blog Entries
    7
    Rep Power
    20

    Default Re: cluster series

    Explain in words how you would do it; no code please.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ameerulislam is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: cluster series

    Quote Originally Posted by JosAH View Post
    Explain in words how you would do it; no code please.

    kind regards,

    Jos
    I don't exactly know. This is why I need your help.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,377
    Blog Entries
    7
    Rep Power
    20

    Default Re: cluster series

    Just give it a try; make that wetware between your ears work.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    ameerulislam is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: cluster series

    Quote Originally Posted by JosAH View Post
    Just give it a try; make that wetware between your ears work.

    kind regards,

    Jos
    This came in my exam today. I couldn't do it there then returned and tried again.. still no real idea. This is why I took the time to write here.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,377
    Blog Entries
    7
    Rep Power
    20

    Default Re: cluster series

    As I wrote before: just give it a try; I know it won't be perfect (otherwise you wouldn't have started this thread), but you have to show some effort instead of begging for a spoonfeeding answer.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ameerulislam is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: cluster series

    Quote Originally Posted by JosAH View Post
    As I wrote before: just give it a try; I know it won't be perfect (otherwise you wouldn't have started this thread), but you have to show some effort instead of begging for a spoonfeeding answer.

    kind regards,

    Jos
    "A try"? I already given several tries. Was I not clear? Never mind..

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,377
    Blog Entries
    7
    Rep Power
    20

    Default Re: cluster series

    Ok, if you refuse to show your tries here ... never mind, goodbye and good luck with it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ameerulislam is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: cluster series

    Ok I think there has been a miss-communication here. I though u were asking to try coding it again. I reread all the posts again and realized you were asking to explain the possible solution for it. Ok here it goes.

    The way I'm trying to solve this problem is this

    Lets go through this input and out put

    Input: {1,1,2,3,3} => Output will be: 2

    first I'll start a loop to see consecutive similar numbers in that array. and add a flag every time it finds two or more consecutive numbers. It will continue to go forward until it gets a different number. So here it will start the loop and when it will see two consecutive 1's then it will increase its counter/flag by 1. Then when it will find 2 which is a different number it will see if there is more 2's after that. Here it will see that there is 3 after 2 so no need to increase the flag. Next it will compare 3 with the next array element. which it will find that there is another 3. Now it will increase the counter / flag by one more. Next when it will reach the end of the array, it will just end the operation I guess.

    I apologize for the miss-communication.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,377
    Blog Entries
    7
    Rep Power
    20

    Default Re: cluster series

    Apologies accepted; back to the problem: suppose you start at position i in your array; also suppose at position i starts a new sequence (this is always true if i == 0). Starting at that position, move to the right until you have reached either the end of the array or the element at the new position doesn't equal the element at position i. Call this position j. The value j-i is the length of the sequence; if it is larger than one, you found a real sequence. Next set i equal to j (one element beyond the sequence) and repeat the above steps until i reaches the end of the array. In code this scenario only requires one loop and a couple of if-statements. Your example:

    1,1,2,3,3 (i= 0, j= 2 --> sequence length == 2)
    1,1,2,3,3 (i= 2, j= 3 --> sequence length == 1)
    1,1,2,3,3 (i= 3, j= 5 --> sequence length == 2)
    1,1,2,3,3,(i= 5 at the end of the array, two 'real' sequences found)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Linux Cluster Management Console 1.0.1
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-10-2011, 07:15 PM
  2. Linux Cluster Management Co...0.9.9
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-05-2011, 06:01 PM
  3. Springs+Cluster+FileDownload
    By j2ee_chap in forum Web Frameworks
    Replies: 3
    Last Post: 04-15-2011, 01:57 PM
  4. Help me with cluster !!
    By ariuka in forum Advanced Java
    Replies: 2
    Last Post: 09-16-2010, 12:40 PM
  5. Cluster using 2 machines
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 06:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •