Question: i, j, and k have been declared as integers, duplicateFound has been declared to be boolean, and a has been declared to be an integer

i, j, and k have been declared as integers, duplicateFound has been declared to be boolean, and a has been declared to be an integer array with at least k+1 cells. duplicateFound = false; for (j = 1; j < k; ++j) for (i = k; i > j; i) if (a[i] == a[j]) duplicateFound = true; The "outer loop" is the "for" loop controlled by the loop index j . The "body of the outer loop" consists, in this example, of another loop, the "inner" (or "nested") loop controlled by the loop index i . The "body of the inner loop" in this example is an "if" statement.

(a) How many times will the body of the inner loop be executed on the first time that the body of the outer loop is executed (i.e., when j has the value 1 ) ? (Express your answer in terms of k .)

(b) How many times will the body of the inner loop be executed on the second time that the body of the outer loop is executed (when j has the value 2 ) ? (Express your answer in terms of k .)

(c) How many times will the body of the inner loop be executed on the last time that the body of the outer loop is executed (when j has the value k1 ) ?

(d) How many times altogether will the test expression a[i] == a[j] be evaluated? Express your answer as an exact polynomial in k .

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!