Thread for Algorithm