Algorithm W.