algorithms
algorithms copied to clipboard
[Oops.] May be there is a error in Figure 1.4
Please verify that the error is present in the most recent revision before reporting.
Chapter number or note title: [title] in Figure 1.4 at 1st edition
Page number: [page] P26 or Figure 1.4 at 1st edition
Error description: [error]
in Figure 1.4
Hanoi(n, src, dst, tmp):
if n > 0
Hanoi(n − 1, src, tmp, dst) 〈〈 Recurse! 〉〉
move disk n from src to dst <<--------- may be error,I'm not certain
Hanoi(n − 1, tmp, dst, src) 〈〈 Recurse! 〉〉
Suggested fix (if any): [fix]
suggested change to:
Hanoi(n, src, dst, tmp):
if n > 0
Hanoi(n − 1, src, tmp, dst) 〈〈 Recurse! 〉〉
directly move disk from src to dst // only this line changed
Hanoi(n − 1, tmp, dst, src) 〈〈 Recurse! 〉〉
explanation:
directly move disk from src to dst <<--------- now n should be 1
thought base on:
Page 22
1.2 Simplify and Delegate
Recursion is a particularly powerful kind of reduction, which can be described
loosely as follows:
• If the given instance of the problem can be solved directly, solve it directly.
• Otherwise, reduce it to one or more simpler instances of the same problem.
it seems like Hanoi(n-1, src, tmp, dst) should be Hanoi(n-1, src, dst, tmp) if the disk no. n is from src to dst. The n-1 disks should be at tmp first.