Optimization And Sampling Using Iterative Algorithms