Algorithm For Best Fit