1. ## Algorithm Trace

In the following algorithm, how many times is the line "z := z + 1" executed if n = 4 and z is an integer?
procedure algor(z,n)
i = 1
while i <= 4 do
begin
z = z +1
n = n – 2
if n > 0 then
algor(z,n)
i = 1 + 1
end
return(z)
end algor

Thanks for the help.
Pwr

2. Originally Posted by pwr_hngry
In the following algorithm, how many times is the line "z := z + 1" executed if n = 4 and z is an integer?

Thanks for the help.
Pwr
As shown, the answer is zero.
There is no n in the problem.

3. Sorry about that. For some reason the image showed up in the Preview but never made it to the final post. Sorry.

Pwr

4. Originally Posted by pwr_hngry
In the following algorithm, how many times is the line "z := z + 1" executed if n = 4 and z is an integer?
procedure algor(z,n)
i = 1
while i <= 4 do
.. begin
.... z = z +1
.... n = n – 2
...... if n > 0 then
........ algor(z,n)
...... i = 1 + 1
.. end
return(z)
end algor

Thanks for the help.
Pwr
The loop is executed exactly four times and the line in question executed once per trip around the loop with n decremented by 2 each time.

The line "if n > 0 then" is arrived at with n=2, 0, -2, -4 and so "algor(z,n)" is executed once with n = 2, and in executing this with n=2 the line in question is executed twice, and the line "algor(z,n)" is never reached.

Hence the line in question is executed 6 times.

RonL