assume perfect binary tree