Question: Consider the algorithm defined below. Input: Non-negative integer n Output: (nothing) Algorithm: WWPowerList t 1 p o w l i s t [1] repeat while

Consider the algorithm defined below.

Input: Non-negative integer n Output: (nothing) Algorithm: WWPowerList

t1

powlist[1]

repeat while tn

t2t

powlistappended(powlist,t)

endrepeat

Let p be the number of elements in powlist, and s be the sum of the entries in powlist.

Just before we enter the loop for the first time:

p =

s=

t =

Let lowercase variables represent values of at the top of the loop (just after the repeat statement, without knowing how many times the loop has been executed), and UPPERCASE variables represent values after one additional pass through the loop (just before the endrepeat). Express the following in terms of values at the top of the loop:

P =

S =

T =

In the space below, explain why s=2t1 is a loop invariant:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!