BMH Algorithm