why is min assigned INT_MAX and mac assigned INT_MIN ?
and how is it working please explain at 2:37
Why is min assigned INT_MAX and max assigned INT_MIN?
Because we are using min(a, b), max(a, b)
operation for this.
Note that this is same as how we initialize s = 0 for sums, because then it doesn’t effect our answer as 0 + anything is = 0.
Similarly for maximum operation, if you initialize with INT_MIN, it won’t affect the answer because everything else is greater than INT_MIN.
1 Like
but if we assign min = INT_MIN
and max = INT_MAX then its affecting answer and showing undesirable values
Yes, that is expected.
If you initialize with INT_MIN, then there is no other element that is smaller than it, therefore, it will always be INT_MIN.
Similarly for INT_MAX.
Note, that INT_MIN = ‘zero’ of maximum function
same as 0 = ‘zero’ of addition function