Question
Question 7 : 9 points Determine the most accurate ( ) for each function. Assume every array has size n. (a) (3 points) The max
Question 7 : 9 points Determine the most accurate ( ) for each function. Assume every array has size n. (a) (3 points) The max method is ( ). 1 int max( int A, int n ){ 2 i f ( n < 2 ) 3 return 1; 4 e l s e i f ( A[ 0 ] > A[ 1 ] ) 5 return A[ 0 ] ; 6 e l s e 7 return A[ 1 ] ; 8 } A. (1) B. (log2 (n)) C. (n) D. (n 2 ) (b) (3 points) The maxElement method is ( ). 1 int maxElement ( int A, int n ){ 2 int l a r g e s t = A [ 0 ] ; 3 for ( int i =0; i < n ; i ++){ 4 i f (A[ i ] > l a r g e s t ) 5 l a r g e s t=A[ i ] ; 6 } 7 return l a r g e s t ; 8 } A. (1) B. (log2 (n)) C. (n) D. (n 2 ) (c) (3 points) The maxSubseqSum method is ( ). 1 int maxSubseqSum ( int A, int n ){ 2 int r e s u l t = A[ 0 ] ; 3 for ( int i =0; i < n ; i ++){ 4 int sum = 0 ; 5 for ( int j=i ; j < n ; j ++){ 6 sum+=A[ j ] ; 7 i f ( sum > r e s u l t ) 8 r e s u l t=sum ; 9 } 10 } 11 return r e s u l t ; 12 } A. (1) B. (log2 (n)) C. (n) D. (n 2 )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started