detect loop in binary tree