jeffgerickson / algorithms

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

[Oops.] Off-by-one error in BuildHuffman pseudocode #206

Open govindbalaji-s opened 4 years ago

govindbalaji-s commented 4 years ago

Please verify that the error is present in the most recent revision before reporting.

Chapter number or note title: Chapter 4 Greedy Algorithms

Page number: 170

Error description: In line 4 of the pseudocode of BuildHuffman , the loop for i <- n to 2n-1 overwrites the nth leaf too.

Suggested fix (if any): Line 4 should be for i <- n+1 to 2n-1