Back Tracking Algorithm