Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. For each of the algorithm segments provided, assume that n is a positive inte

ID: 3548819 • Letter: 1

Question

1.     For each of the algorithm segments provided, assume that n is a positive integer. Compute the actual numbers of additions, subtractions, multiplications, divisions, and comparisons that must be performed when the algorithm segment is executed. For simplicity, however, count only comparisons that occur within if-then statements; ignore those implied by for-next loops.

a.         for i :=3  to  n?1

a := 3 * n + 2 * i

For each of the algorithm segments provided, assume that n is a positive integer. Compute the actual numbers of additions, subtractions, multiplications, divisions, and comparisons that must be performed when the algorithm segment is executed. For simplicity, however, count only comparisons that occur within if-then statements; ignore those implied by for-next loops. for i :=3 to n?1 a := 3 * n + 2 * i - 1 next i for i := 1 to ?n/2? a := n - i next i

Explanation / Answer

1st Loop


The loop runs for n-1-3 ie n-4 times.

a := 3 * n + 2 * i