Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Count the Footsteps

Learn
Play
Prove
Lesson 1 of 4

Live algorithm trace

Sum one complete array

Complete execution
1 of 5

Initialize the running total before reading [4, 1, 3].

1total = 0
2for each x in nums
3total += x
4return total
total = 0

Algorithms solve the same task for many input sizes. We call the number of input items n. In this trace, [4, 1, 3] has n = 3. Start total at zero, add each value once, then return after the loop. After every step, total is the sum of the values already visited.

Your call · An array contains 32 values. What is n?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead