Common Array Algorithms
11. Classic Bug (2): Big Negatives
Answer:
The maximum is -12.
Classic Bug (2): Big Negatives
Classic Bug (2): It is tempting to say that the maximum is -92, since -92 seems to be a bigger number than -12. But this confuses the absolute value of a number with its position on the number line. If you are looking for the maximum of a list of numbers, you are looking for the number which is furthest to the right on the number line, even if the number is negative.
Think of this as pay. If Jill is paid -92 dollars a day and Joe is paid -12 dollars a day, who is paid the most? (And exactly which fast food restaurant do they work at?)
The minimum of a list of numbers is the one furthest to the left on the number line.
Question 11:
What is the minimum of our list of integers:
-45, -23, -87, -56, -92, -12, -36