ICS/CSE 23 Introduction to Computer Science III Quiz 1

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

ICS/CSE 23 Introduction to Computer Science III  Quiz 1

1. Below is a recursive method which will reverse an array of items. Fill in the two blank lines according to the comments given. 

ReverseArray( A ) 

ReverseArrayRecursive( A, 0, A.length - 1 ); 


ReverseArrayRecursive( A, low, high ) 

//fill in the check for the base case 

________________________________________ 

Swap( A[low], A[high] ); 

//write the recurive call below 

_________________________________________

 } 

2. Give the running time (in Big-Oh notation) of the methods below. Simplify your answer as much as possible. 

(a) boolean containsDuplicate( int[] A ) 

for ( int i = 0; i < A.length; i++ ) 

for ( int j = 0; j < i; j++ ) 

if ( A[i] == A[j] ) 

return true; 

return false; 

(b) boolean containsNegativeOrDuplicate( int[] A ) 

for ( int i = 0; i < A.length; i++ ) 

if ( A[i] < 0 ) 

return true; 

for ( int i = 0; i < A.length; i++ ) 

for ( int j = 0; j < i; j++ ) 

if ( A[i] == A[j] ) 

return true; 

return false; 

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注