In “Reduce a number to one in Minimum number of steps” why are the queries initialized to infinity?
Why were queries initialized with infinity?
HI @akh.chakraborty11, we need to reach 1 asap and when we perform any operation we need to compare it’s result with a previous result. Now when we operate for the first time on the number we have only one result and we need to carry it forward so that when the 3 operations are performed again we can compare the values again.
When we have performed the operation for first time we know that there’s no other value that it can be compared rto but we also know that this is the best ans so far hence we initialize the variables with infinity so that in first comparison the minimum value will be the result generated after 1st operation as it will always be smaller than INF.
Hope this helps
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.