Update# added the 2nd algorithm