Answer: Choice C
Algorithm Il always works correctly, but Algorithm I only works correctly when the maximum value is greater than or equal to - 1
=====================================================
Step-by-step explanation:
Let's say we have the data set {-4,-3,-2}. The value -2 is the largest.
If we follow algorithm 1, then the max will erroneously be -1 after all is said and done. This is because the max is set to -1 at the start even if -1 isn't in the data set. Then we see if each data value is larger than -1.
- -4 > -1 is false
- -3 > -1 is false
- -2 > -1 is false
Each statement being false means we do not update the max to its proper value -2. It stays at -1.
This is why we shouldn't set the max to some random value at the start.
It's better to use the some value in the data set to initialize the max. Algorithm 2 is the better algorithm. Algorithm 1 only works if the max is -1 or larger.