0% found this document useful (0 votes)
60 views

Solution of Exercise C-4.1: Data Structures and Algorithms in Java

The document provides the solution to an exercise problem about a recursive algorithm called product(n, m) that computes the product of n and m using only addition and subtraction. The algorithm recursively calls itself, returning n if m is 1, and otherwise returns n plus the result of calling product(n, m-1).

Uploaded by

xcygon
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Solution of Exercise C-4.1: Data Structures and Algorithms in Java

The document provides the solution to an exercise problem about a recursive algorithm called product(n, m) that computes the product of n and m using only addition and subtraction. The algorithm recursively calls itself, returning n if m is 1, and otherwise returns n plus the result of calling product(n, m-1).

Uploaded by

xcygon
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Data Structures and Algorithms in Java

(Third Edition)
M. T. Goodrich and R. Tamassia
John Wiley & Sons
Solution of Exercise C-4.1
The recursive algorithm, product(n, m), for computing product using only
addition and subtraction, is as follows: If m = 1 return n. Otherwise, return
n plus the result of a recursive call to the method product with parameters
n and m − 1.

You might also like