Page 1 of 1

Question 7 Question 1g Consider the following STRANGE ALGORITHM: Algorithm 1 STRANGE ALGORITHM Require: Integer n 1: S+0

Posted: Tue May 24, 2022 8:28 am
by answerhappygod
Question 7 Question 1g Consider The Following Strange Algorithm Algorithm 1 Strange Algorithm Require Integer N 1 S 0 1
Question 7 Question 1g Consider The Following Strange Algorithm Algorithm 1 Strange Algorithm Require Integer N 1 S 0 1 (60.5 KiB) Viewed 27 times
Question 7 Question 1g Consider the following STRANGE ALGORITHM: Algorithm 1 STRANGE ALGORITHM Require: Integer n 1: S+0 2: for i← 1 ... n do 3: if i is odd then S+S-i 4: 5: else 6: S+S+i 7: end if 8: end for 9: return S Which of the following loop invariants is correct? At the beginning of iteration; (i.e., after; is updated in Line 2 and before the code in Line 3 is executed) the following property holds: OS-(-1)(1/2) if ; is odd and S-(-1)(i-1)/2 if ; is even OS=-(i+1)/2 if; is odd and S = 1/2 if; is even S-(-1)+³((i-1)/2) if; is odd and S-(-1)+¹(1/2) if ; is even OS-1/2-0.5 ifi is odd and S= -1/2 if ; is even