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 𝑠𝑠𝑠𝑠𝑠𝑠

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly