1. Consider the following algorithms:
procedure alg1 (a, b: positive integers)
x:=a
y:= b
while y ? 0
y:= y + 1
x:=x+a
return x
procedure alg2 (a, b: positive integers)
x:=a
y:= b
while y ? 0
r := x mod y
x:= y
y:= r
return x
For each algorithm, decide whether it is finite or not. Here, an algorithm is said to be finite
if its computation guaranteed to terminate no matter which positive integers are chosen for
the input a and b? For full credit, give your answer ("yes" or "no") and justify it. That is,
• If your answer is "yes," the justification should explain why the algorithm can't possibly
go into an infinite loop no matter what inputs are chosen (think carefully about the type
of the inputs and the loop condition).
• If your answer is "no," you need to find an example where the algorithm never returns
output because it goes into an infinite loop.