code for various algos