binary tree puzzle functions