algorithms simple functions