Implemented the binary tree algorithm.