iterative and recursive solutions