For each of the below code snippets, identify the bounding function (the big O) of the number of times the indicated line is run (justify your answer briefly): int i = 1: while (i
Expert Answer
int i = 1;
while (i < n) {
printf(“Insert difficult work here!”); (This Line)
i = i +1;
}
The complexity is of O(n). The loop is running for n times as i starting with 1 and going up to n.
for(i=0; i<n; i++) {
for(j=0; j<n; i++) {
for(k=0; k<n; i++) {
if (i==j && j==k)
arr[i][j][k] = 1; (This Line)
}
}
}
This is again O(n) . For i = 1 the statement will be executed only once (i.e j = 1 && k = 1). So it means that for each value of i, the statement will be executed once and i is going from 1 to n so it is of order(n)