jeffgerickson / algorithms

Bug-tracking for Jeff's algorithms book, notes, etc.
7.91k stars 1.02k forks source link

[Oops.] PlaceQueens pseudocode bug #201

Open protik77 opened 4 years ago

protik77 commented 4 years ago

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.

pooyataher commented 2 years ago

@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

chamip commented 2 years ago

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