It depends on the data type you're using. -∞
and +∞
simply mean the lowest and highest values possible.
If you pick int
, the respective values can be Integer.MIN_VALUE
and Integer.MAX_VALUE
. The algorithm will work just fine.
Also, infinity can be represented in Java. If you really want to, you can use float
, which has both a positive and negative infinity value. You could just use Float.POSITIVE_INFINITY
and Float.NEGATIVE_INFINITY
. For this algorithm,though, I'd stick with integers. Just because they're free from all possibly unexpected behavior related to rounding and precision.