Question: Include its pre-conditions and post-conditions. Finally, prove by induction that the recursive algorithm is correct Given the following iterative algorithm which computes the nth triangular
Include its pre-conditions and post-conditions. Finally, prove by induction that the recursive algorithm is correct
Given the following iterative algorithm which computes the
nth triangular number:
int tri(int n)
{
int result = 0;
for (int i = 1; i = n; i ++)
result += i;
return result;
}
Convert this function to use recursion. Include its pre-conditions and post-conditions. Finally, prove by induction that the recursive algorithm is correct
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
