Implement HV binary tree algorithm