IBM Research | Ponder This | March 2012 solutions
Skip to main content

March 2012

<<February March April>>

The question is about graceful labeling of balanced binary trees (see

There are many ways to solve this problem: genetic algorithms; standard searching techniques; SAT solvers; etc.

But there is also an analytic solution:

Let n denote the tree height. In our case, n=6.

Denote by h(i) the Hamming weight function and by l(i) the truncated log_2 function.

The following function f computes as f(i) (for 1 <= i <= 2**n-1) the required answer:

[-(-1)**(n-l(i)) * [int(l(i)/2)+2-h(i)+i*2**(n-l(i))]] mod (2**n)

The output for n=6, in the format we asked for is as follows:


One of the solvers asked us why all the solutions have an odd number at the root.

There is an elegant simple proof for that. Can you find it?

If you have any problems you think we might enjoy, please send them in. All replies should be sent to: