In: Computer Science
Given the below code, compute the values of the best case, worst case and average case knowing that the basic operation in the first loop takes 4 ns to execute and the basic operation in the second loop takes 5 ns to execute.
int A[20];
for (int i=0; i < 20; i++)
{
cin >> A[i];
}
for (i=0; i < 20; i++)
{
if (A[i] % 3 == 0)
break;
}
The first loop inputs 20 elements, thus the total time for the first loop
= 20 * (4 ns)
= 80 ns
Now, following are the possibilities for second loop :
= 52.5 ns
Thus, total times in