add memo for 1.2.2 tree recursion