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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started