Answer:
(a) 4i iterations
(b) "i × n" iterations
Step-by-step explanation:
(a) The provided algorithm segment shows:
for i:= 1 to 4, (Outer loop)
for j:= 1 to i (Inner loop)
next j,
next i
The inner loop executes i times while the outer loop completes 4 cycles.
The inner loop’s total execution when the full algorithm runs is:
= i × 4
= 4i iterations
(b) In the given algorithm segment;
for i:= 1 to n, (Outer loop)
for j:= 1 to i (Inner loop)
next j,
next i
where n denotes a set of positive integers.
<pthe inner="" loop="" also="" runs="" for="" times="" and="" the="" outer="" times.=""><pthus the="" total="" iterations="" of="" inner="" loop="" for="" entire="" algorithm="" is:="">
= i × n
= "i × n" iterations
</pthus></pthe>