basic algorithms implemented in c