adding non-uniform (in D) algorithm from Lynch paper