Implement binary H tree algorithm