Subtree finder algorithm implemented