implement some basic algorithms