Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following problem: A person is about to climb a staircase of n stairs. Each step she makes can be either a regular-size step

Consider the following problem: A person is about to climb a staircase of n stairs. Each step she makes can be either a regular-size step that climbs 1 stair, or a big-size step that climbs 2 stairs. In how many di erent ways can she climb the whole set of n steps ? E.g., for climbing 3 stairs she has 3 possible ways: (reg,reg,reg), (reg,big), (big,reg). Note you don't need to explicitly write her steps but only the number of options she has. Write a recursive solution for solving the problem.

Hint: Think about the base cases ; then look at her last step to de ne the smaller instances and transition: it is either reg or big. If it is reg, then she rst has to get to stair n-1; if it is big, she rst needs to get to stair n-2. Does it seam familiar ?

In pseudocode like below and word descriptionimage text in transcribed

procedure FindMax (A, n) if (n=1) then return Al1 else return max(A[n], FindMax (A, n - 1))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions