Answer:
(a) 4i times
(b) "i × n" times
Step-by-step explanation:
(a) Given the algorithm segment;
for i := 1 to 4, (Outer loop)
for j := 1 to i (Inner loop)
next j,
next i
The inner loop runs for i times, while the outer loop runs for 4 times.
The total times the inner loop would run when the entire algorithm is run is:
= i × 4
= 4i times
(b) Given the algorithm segment;
for i := 1 to n, (Outer loop)
for j := 1 to i (Inner loop)
next j,
next i
Where n is a set of positive integers.
The inner loop runs for "i" times, while the outer loop runs for "n" times.
The total times the inner loop would run when the entire algorithm is run is:
= i × n
= "i × n" times