Question: Problem 2 . ( 3 0 marks ) Consider this alogrithm: ` ` ` / / pre: array A of length n , each A

Problem 2.(30 marks)
Consider this alogrithm:
```
// pre: array A of length n, each A[i] is picked randomly uniformly
// from the set {0,1,2,3,4,5,6,7,8,9}.
// post: return the index of the first occurrence of "check digit" of A
//(already computed in the code)
// return -1 if check digit is not found
int FindCheckDigit(A){
check_digit =0
for (i=0; i n; i++)
check_digit = check_digit + A[i]
check_digit = check_digit %10 # % means remainder of division
for (i =0; i n; i++){
if (A[i]== check_digit){
return i
}
}
return -1;
}
```
Compute the average runtime for this algorithm. Show all details of your computation for both loops.
Problem 2 . ( 3 0 marks ) Consider this

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 Programming Questions!