
CSP Explanation
Saw many people in someone's previous post arguing that its D. However, I believe that the answer is C and am confused why everyone says it's D.
Here's why I believe it's C and not D:
Let List be equal to [1, 3]
Let's hand trace this
ALGORITHM #1:
sum = 0
count = 1
sum = 0 + 1 = 1
count = 1 + 1 = 2
Count is equal to 2 (the length of list)-->Don't iterate again (loop is done)
ave = 1/2 = 0.5
Return 0.5
Incorrect average, Algorithm A has failed.
ALGORITHM #2:
sum = 0
count = 1
sum = 0 + 1 = 1
count = 1 + 1 = 2
ave = 1/2 = 0.5
Count is equal to 2 (the length of list)-->Don't iterate again (loop is done)
Return 0.5
Incorrect average, Algorithm B has failed.
CONCLUSION:
Essentially, both algorithms will, in all cases, prevent us from considering the value of the last item in our list because when count increases to list.length (the index of the last item in our list), the REPEAT UNTIL loop ends before we can add the last item to our sum, ultimately leading to an incorrect average.
I believe this question is extremely poorly written by Barron's. Barron's claims the answer is D which, as I've shown above, I think is inaccurate.
Please don't hesitate to correct me if I'm wrong!