code for algorithms