algorithms icon indicating copy to clipboard operation
algorithms copied to clipboard

[Oops.] PlaceQueens pseudocode bug

Open protik77 opened this issue 6 years ago • 2 comments

Chapter number or note title: Chapter 2, Figure 2.2

Page number: 73

Error description: The line 6 of the pseudocode reads for i <- 1 to r-1. The first call would be PlaceQueens(Q[1..n],1) where r=1. This sets the line 6 to, for i <- 1 to 0.

Suggested fix (if any): NA.

protik77 avatar Feb 06 '20 21:02 protik77

@protik77 Your description seems accurate, but it doesn't seem to cause any error in executing the pseudocode. In the situation you described, the loop body is simply skipped and not executed. This seems to be the case not only in this pseudocode, but also in popular programming languages such as Python or C. For example, the following Python loop will never execute the print statement in the loop body.

for i in range(1, 1):
    print('you will never see this message')

Neither will the following C loop ever execute the printf statement in the loop body.

for (int i = 1; i < 1; ++i)
    printf("you will never see this message\n");

Note that the two loops above are arguably the closest implementation of the one used in the pseudocode, that is, for i <- 1 to 0

pooyataher avatar Jan 11 '22 20:01 pooyataher

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

chamip avatar Jan 11 '22 20:01 chamip