concept: Looping constructs (e.g. while or for loops) lead naturally to iterative algorithms
def iterMul(a, b): result = 0 while b > 0: result += a b -= 1 return resultReduce a PRoblem to a simpler (or smaller) version of the same problem, plus some simple computations
Recursive step– Keep reducing un0l reach a simple case that can be solved directly
Base case def recurMul(a, b): if b == 1: return a else: return a + recurMul(a, b-1)新闻热点
疑难解答