Fast Search-based Algorithm for Smooth and Nonsmooth Optimization, with Some Applications in Imaging