Solution to Recursion Josepheus Problem

42 Views Asked by At

In the book we have the recursion

$J(1) = 1 $

$J(2n) = 2J(n) - 1, $ for $ n \ge 1$

$J(2n + 1) = 2J(n) + 1, $ for $ n \ge 1 $


The solution give is $ J(2^m + l) = 2l + 1$

which is I feel is equal to $J(n) = 2(n - 2^m) + 1$ where $ n = 2^m + l $



But when we take $J(\frac{2^m + l}{2}) = J(\frac{n}{2})$ we get

$J(\frac{2^m + l}{2}) = 2\frac{l}{2} + 1 = l + 1$

$J(\frac{n}{2}) = 2(\frac{n}{2} - 2^m) + 1 = n - 2^{m + 1} + 1$

which seems to say that $n = 2^{m + 1} + l$, which is confusing to me. I don't think that n should change?

1

There are 1 best solutions below

2
On

Note that $m,l$ are not any.

Given a positive integer $n$ then there exists a couple of non negative integers $m,l$ such that

$n = 2^m + l$ with

$$ m = \arg\max_m 2^m = n-l\ge 0 $$

Ex.

$$ n = 1177_{10} = 10010011001_2\Rightarrow n = 2^{10}+153 $$