Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(c) Consider the following algorithm for computing the factorial of some integer n>=2 . procedure FACTORIAL (n) i=1 j=1 while j=j+1i=i**jiji=jj do
(c) Consider the following algorithm for computing the factorial of some integer
n>=2
.\ procedure FACTORIAL
(n)
\
i=1
\
j=1
\ while
j=j+1i=i**jiji=jj do\ j=j+1\ i=i**j\ end while\ return i\ end procedure\ (i) (8 points) To prove the correctness of this algorithm, the following loop invariant for the while loop in lines 4-7 can be defined:\ Loop Invariant: At the start of iteration j, it must be that i=j !\ Prove correctness by showing that this loop invariant is true using the initialization, maintenance, and termination properties.\ (ii) (2 points) Compute the worst-case running time.\ 2
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