Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: time complxity

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default time complxity

    The program below accept two array with hole pozitive nums, with same size N, and fill empty array "c" with nums of "a" that do not exist in "b" and return the biggest num of "a" that do not exist in "b".
    qustion: how to do write this method with more efficiency ?

    public int f(int[]a, int[]b, int[] c)
    	{
    		int N = a.length;
    		int j, max = 0, g = 0, t = 0;
     
    		for(int i=0; i < N; i++)
    		{
    			for(j=0; j<N; j++)
    				if(b[j] == a[i]) // if find the num in "b" go to the next num in "a"
    				   break;  
     
    			if(j == N)
    			{
    				c[t] =a[i]   // fill empty array "c" with nums of "a" that do not exist in "b"   
                                                            if(g ==0 || c[t] > max)
    				{
    					max = c[t]; // remmber the max num in "max"
    					g = 1; 
     
    				}
    				t++;
     
    			}	
     
     
    		}
    		return max; // max of "a" that you do not have in "b"


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: time complxity

    What have you tried? Where are you stuck? We can't just do your homework for you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: time complxity

    romavolman, please read the forum rules. This is your second time duplicate posting, the first you were told to read the forum rules, which you apparently haven't. Double posting again and you will receive a more strict warning.
    Thread locked as duplicate of http://www.javaprogrammingforums.com...fficiency.html

Similar Threads

  1. [SOLVED] Help with time
    By usama8800 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 25th, 2012, 04:13 PM
  2. Two different streams at same time
    By ToshX in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 4th, 2011, 02:55 PM
  3. First Time
    By rayoung17 in forum Member Introductions
    Replies: 1
    Last Post: April 4th, 2011, 01:52 PM
  4. Using time
    By ellias2007 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 4th, 2010, 08:48 AM
  5. display time
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 1st, 2010, 07:40 AM