We want to count the number of possible paths to move from row 1, column 1 to

Question:

We want to count the number of possible paths to move from row 1, column 1 to row N, column N in a two-dimensional grid. Steps are restricted to going up or to the right, but not diagonally. The illustration that follows shows three of many paths, if N = 10:

image text in transcribed1. The following function, NumPaths, is supposed to count the number of paths, but it has some problems. Debug the function.

image text in transcribed2. After you have corrected the function, trace the execution of NumPaths with n = 4 by hand. Why is this algorithm inefficient? 

3. You can improve the efficiency of this operation by keeping intermediate values of NumPaths in a twodimensional array of integer values. This approach keeps the function from having to recalculate values that it has already figured out. Design and code a version of NumPaths that uses this approach. 

4. Show an invocation of the version of NumPaths you developed in part (c), including any array initialization necessary. 

5. How do the two versions of NumPaths compare in terms of time efficiency? Space efficiency?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

C++ Plus Data Structures

ISBN: 9781284089189

6th Edition

Authors: Nell Dale, Chip Weems, Tim Richards

Question Posted: