Assignment: Time complexity

Due Monday, 2/24/03

  1. Consider the following method:

    
    public static boolean something( char[] a, char ch )
    {
    	int N = a.length;
    	for( int i=0; i < N; i++ )
    	{
    		if( a[i] == ch )
    			return true;
    	}
    
    	return false;
    }
    

  2. Consider the binarySearch method on page 486 of Wu.

  3. I have an array of integers, and I want to know the distance between the pair of these numbers that are furthest apart. Elmo suggests the following code, which does the job:

    
    public static int elmo( int[] a )
    {
    	int max = 0;
    	for( int i=0; i < a.length; i++ )
    	{
    		for( int j=0; j < a.length; j++ )
    		{
    			if( a[i] - a[j] > max )
    				max = a[i] - a[j];
    		}
    	}
    
    	return max;
    }