Question: Devise a recursive algorithm for computing n 2 where n is a nonnegative integer, using the fact that ( n + 1 ) 2 =
Devise a recursive algorithm for computing where is a nonnegative integer, using the fact that Then
prove that this algorithm is correct.
procedure square : nonnegative integer
if then return
else return square
Let be the statement that this algorithm correctly computes Because the algorithm works correctly
using the if clause if the input is Assume that the algorithm works correctly for input Then for input it
gives as output because of the else clause its output when the input is plus By the inductive
hypothesis, its output at is so its output at is as desired.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
