code for algorithm in