Implementation of BiPartite algorithm