Question: This pseudo (Python) counts the number of ways a person could walk up a set of n stairs where they can either take 1, 2,

This pseudo (Python) counts the number of ways a person could walk up a set of n stairs where they can either take 1, 2, or 3 stairs at a time. Takes an int indicating the number of stairs to be climbed and returns an int indicating how many different ways the stairs could be traversed.

Explain what the pseudo code is doing and trace the code for countWays(5).

countWays(stairs)

if stairs < 0

return 0

else if stairs == 0

return 1

else

return countWays(stairs-1) + countWays(stairs-2) + countWays(stairs-3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!