implemented 1st algorithm