cart algorithm