Let T(n) represent the count of numbers which occur before n is eventually reduced to <=1.
T(n)= 0 if n is 1 or 0
1+ T(n/2) if n is even
1+ T(3*(n+1)) if n is odd
So, if value of T(n) can be calculated , then the program will terminate otherwise not.
I begin with the case where n is odd.
Lets start with smallest possible odd number n =3; the course of solution will be as follows => T(3)->T(12)->T(6)->T(3)
We can see that this is an infinite loop
Similarly , we can observe with n=5
T(5)->T(18)->T(9)->T(30)->T(15)->T(48)->T(24)->T(12)->T(6)->T(3)
Again the infinite loop
Similarly I observed for n=7 too..
However, I do not have any mathematical proof which confirms this, But there is counter example to contradict this.
I know this problem could be done through cycle detection too. But will it not be more time consuming solution specially considering the fact that n is of the order of 10^14.?
Does any one has a counter example where the number is not of the form 2^x and still the program is terminating. Of course n is should not be 0.