Page 1 of 1

Question 1g Consider the following STRANGE ALGORITHM: Algorithm 1 STRANGE ALGORITHM Require: Integer n 1: S-0 2: for i+1

Posted: Tue May 24, 2022 8:34 am
by answerhappygod
Question 1g Consider The Following Strange Algorithm Algorithm 1 Strange Algorithm Require Integer N 1 S 0 2 For I 1 1
Question 1g Consider The Following Strange Algorithm Algorithm 1 Strange Algorithm Require Integer N 1 S 0 2 For I 1 1 (32.08 KiB) Viewed 13 times
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 iis 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) ifi is odd and S-(-1)(-1)/2 if is even OS--(+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 S-1/2-0.5 ifi is odd and S--1/2 ifiis even