missionary algorithm