Introduction to Algorithms Flashcards
1
Q
Iterative
A
Iterative (βbottom-upβ): A loop structure builds up to a solution.
SUMSQUARESITERATIVE(ππ)
π π π π π π = 0
forππ=1to ππ
π π π π π π =π π π π π π +ππ2
return π π π π π π
2
Q
Recursive
A
Recursive (βtop-downβ): The algorithm calls itself on smaller instances of the same problem.
SUMSQUARESRECURSIVE(ππ)
if ππ==1
return 1
else
return SUMSQUARESRECURSIVEππβ1+ππ2