Question: Consider the following pseudocode function. The index of array data starts at 0 . / / precondition: N is the length of the array data

Consider the following pseudocode function. The index of array data starts at 0.
// precondition: N is the length of the array data
int moat_after ( int array data, int x )
int moat 0
for ( int i 0; i < N; i i +1)
int current 0
for ( int j i +1; j < N; i j +1)
if ( data[i]== data[j])
current current +1
end if
end for
if ( current > moat )
moat current
end if
end for
return moat
end moat_after I
f array data has N elements, what is the average running time of function moat_after?
A. O(N)
B. O(NlogN)
C. O(n^2)
O(n^3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!