sir in the even case , we did not consider f(i+1) in our calculation because you have said it would take more time.
sir please explain me
Cell metosis hackerblock
hello @mzk1994
say if i is even then
f(i) = min(f(i-1) , f(i+1) , f(i/2) )
now becuase i is even i+1 will be odd so here we cannot perform division step , only option we are left with is either add one to it or subtract one to it.
so
i+1 will become -> (i+2) on adding or i (on subtracting ,discard this as we reached fthe same from where we started)
f(i) = min(cost of subtracting + f(i-1), cost of div + f(i/2) , cost of adding 2 ones + f(i+2) )
f(i+2 /2 ) -> cost of div + f(i/2)
here u can see we have extra cost for div and 2 cost of adding.
thats why we discarded this state.
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.