Variant of Johnson algorithm