Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please post proof rules used if the proof is correct. Following are four functio

ID: 3786979 • Letter: P

Question

Please post proof rules used if the proof is correct.

Following are four functions intended to return the value a[1] + a[2] + ...+ a[n] for n lessthanorequalto 1 (the sum of the first n entries in an array of integers). For those that do not produce correct results, explain what goes wrong. For those that do produce correct results, do a proof of correctness. ArraySumA (integers n, a[1], a[2], ..., a[n]) Local variables: integers i, j I = 0 j = 0 while i lessthanorequalto n do I = I + 1 j = j + a[i] end while//j now has the value a[1] + a[2] + ... + a[n] return j end function ArraySumA

Explanation / Answer

No,the proof is not correct. The only mistake is the condition in while loop. It should be while i<n as the range of the index of array starts from 0 - (n-1) . So, if we use the given condition then array out of bounds error will be generated.And another mistake is that first i value is incremented therefore , first element value is never calculated

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote