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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 11 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply