Question
Database Structure Question 39 Not yet answered Marked out of 1.00 Not flaggedFlag question Question text For the following code fragment, select the option which
Database Structure
Question 39 Not yet answered Marked out of 1.00 Not flaggedFlag question Question text For the following code fragment, select the option which represents the most appropriate asymptotic analysis:
static int function ( n ) {
sum = 0;
for (i=1; i<=n; i++)
sum += n;
return sum;
}
Option 1. ( n2 )
Option 2. ( n )
Option 3. O( log n )
Option 4. O( 2n )
(NOTE: code fragment is not intended to be functioning code)
Select one: a. Choice 1 b. Choice 2 c. Choice 3 d. Choice 4
29)
For the following code fragment, select the choice which represents the most appropriate asymptotic analysis:
/* @return The position of an element in sorted array A with value k. If k is not in A,return A.length. /
static int binary(int[] A, int k) {
int l = -1; // Set l and r
int r = A.length; // beyond array bounds
while (l+1 != r) { // Stop when l, r meet
int i = (l+r)/2; // Check middle
if (k < A[i]) r = i; // In left half
if (k == A[i]) return i; // Found it
if (k > A[i]) l = i; // In right half
}
return A.length; // Search value not in A
}
Choice 1. ( n )
Choice 2. O( 2n )
Choice 3. O( log n )
Choice 4. ( n2 )
(NOTE: code fragment is not intended to be functioning code)
Select one: a. Choice 1 b. Choice 2 c. Choice 3 d. Choice 4
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