Johnson's algorithm