Errata

Algorithms in a Nutshell

Errata for Algorithms in a Nutshell

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page xi
Last paragraph

"We provide live code examples, and in the accompanying code repository..."

I was baffled for a while trying to figure out where the accompanying code repository was provided. There are no obvious links from the O'Reilly page for the book. I didn't immediately see a url in the text, nor was it in an appendix and particularly the preface.

I did find some code linked from the Author's Blog, downloaded, and discovered this note in the README:

"We intend to release updated versions of the repository based upon any
identified problems. You likely are already aware of the SVN repository
from which you downloaded this release:

http://examples.oreilly.com/svn/examples/9780596516246/"

The above link doesn't work. It looks like C++ solutions are provided for a subset of the algorithms. For example, only Java is provided for Network Flow algorithms. This should be mentioned when discussing the code in the preface.

DocSavage  Mar 26, 2010 
PDF Page 14
3rd paragraph

The text says
=====
Although Sort-4 from Figure 2-1 was the slowest of the four algorithms for sorting n random strings, >>> it turns out to be the fastest when the data is already sorted <<<. This advantage rapidly fades away, however; with just 32 random items out of position, as shown in Figure 2-2, Sort-3 now has the best performance.
=====

whereas on the picture 2.2 with sorted data sort-4 is not the fastest one, but sort-1

Alex  Aug 29, 2019 
Printed Page 22
Topmost formula

The formula for Tac (average case running time of an algorithm) is wrong.

The formula in book is confusing/merging two separate ways to calculate it.

If we have a probability distribution then Tac is:

Tac = SIGMA( t(s) * P{input is s} ) over all s in S

If we assume a uniform distribution then Tac can be calculated as:

Tac = 1/|S| * SIGMA( t(s) ) over all s in S


Anonymous  Jan 14, 2013 
Printed Page 24
Example 2-1

There is a subtle bug in the implementation of the turns() function in Example 2-1. The calculation of the midpoint will overflow to a negative integer whenever low + high is larger than 2^31 - 1 (i.e. Integer.MAX_VALUE).

So, for example, we have:

turns(1, 1, 100) = 6

but if we offset n, low, and high by a constant, we get a different answer:

turns(1073742801, 1073742801, 1073742900) = 2

Note that these arguments are in the neighborhood of 0.5 * Integer.MAX_VALUE, and not exceptional.

Instead of calculating the midpoint this way,

int mid = (low + high)/2;

instead use

int mid = low + ((high - low) / 2);

Don't worry, you're in good company:

http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html

deisner  Jul 27, 2010 
Printed Page 44
Half way in source listing

double firstAngle = ... should be '- lowestY' and not '-lowest'.
Same with the next line starting with 'double lastAngle ='.

Anonymous  Sep 26, 2016 
PDF Page 58
2 para

"For notational convenience, we define <<A[low, low+n)>> to be the subcollection A[low] ... A[low+n?1] of n elements, whereas <<A[low,low+n]>> describes the subcollection A[low] ... A[low+n] of n+1 elements."

The two highlighted expressions <<>> appear to be identical, ie A[low, low+n] yet they define two different subcollections. I find this confusing.

Anonymous  Mar 26, 2013 
Mobi Page 67
United States

In figure 4-8 for Median Sort, line 5, where it says:

for left=0 to mid-1 do

it should say instead:

for i=0 to mid-1 do

Will Ekiel  Oct 16, 2013 
PDF Page 72
2nd paragraph

The text:

The selectKth function must select a pivotIndex ...

should be

The selectPivotIndex function must select a pivotIndex ...

since it is the selectPivotIndex function that selects the pivotIndex and not the selectKth function.

Anonymous  Jan 16, 2014 
Printed Page 73
Tbel 4-2

When checking the results for the performance (in seconds) of Median Sort in the worst case (table 4-2) and average case (table 4-3), the results for the average case are much worse than the worst case. I'm trying to understand these results by going through the description of each tested case bu I'm not able to identify what exactly could lead to this big different. Is there any explanation for this?

Anonymous  Dec 22, 2018 
79
Figure 4-11, partition function

Why

if (A[i] &#8804; A[right]) then

and not just

if (A[i] < A[right]) then

? This way there are fewer swaps and increments and it's not more complicated, and either way it's not a stable sort.

Rui Baptista  Aug 01, 2011 
Printed Page 94
Figure 4-18, Line 3, extract method

Dear Mr. Heineman,

In the extract method (Line 3) of the BUBBLE SORT algorithm, shouldn't the insertion sort be performed on B[i] instead of the whole bucket B? Isn't each bucket an array in itself?

Alternately, could we sort all the buckets in B using INSERTION SORT prior to the 'for' loop in Line 2?

Please clarify.

Thanks,
Hari Samala

Hari Samala  Sep 23, 2012 
Printed Page 94
Figure 4-18, extract function line 4

In line 4 of the extract function in Figure 4-18 on p. 94, the line is
"for m = 1 to size(B[i]) do"

However, should this be "for m = 0 to size(B[i]) - 1 do"?

Since B[i] is an array, the first element starts at index 0, not index 1. So if we use m = 1, the first element in bucket B[i] at index 0 is never assigned to the array A. I think we need to start with m = 0 if we are to assign each element in bucket B[i] to array A...

Anonymous  May 03, 2017 
PDF Page 97
below the source code listing

Author claims that the linked list implementation is about 30-40% faster what IMHO is not true.
Array is the best container for small number of elements. Linked list is able to outperform an array only when dealing with huge number of elements. One of the reason is that a linked list isn't cache friendly.
Now, the algorithm assumes uniform distribution. Consequently, each bucket shall contain single element on average. In this situation, an ordinary array should be the best choice. I compiled and ran the code and I was surprised. The implementation with linked list was better. I went through source code and I found this in the array based implementation:
#define BUCKET SIZE 16
Allocating memory for 16 elements make no sense if we expect one element per bucket on average. I changed it to 2 and reran my test:
#define BUCKET SIZE 2
As I suspected, the array based implementation is better.
Here are my results:

Linked list:
N =2000, time=0
N =4000, time=0
N =8000, time=0
N =16000, time=1
N =32000, time=2
N =64000, time=7
N =128000, time=18
N =256000, time=44
N =512000, time=100
N =1024000, time=215
N =2048000, time=448
N =4096000, time=930
N =8192000, time=1837
N =16384000, time=4064
N =32768000, time=8641

Array:
N =2000, time=0
N =4000, time=0
N =8000, time=2
N =16000, time=2
N =32000, time=2
N =64000, time=5
N =128000, time=17
N =256000, time=38
N =512000, time=81
N =1024000, time=172
N =2048000, time=357
N =4096000, time=743
N =8192000, time=1414
N =16384000, time=3135
N =32768000, time=6584

Wojciech Jabłoński  Jun 18, 2015 
Printed Page 116
Variations: 1st paragraph

It says the final value of ix identifies the index value which the missing element can be inserted. It should be the 'low' index.

If array [1,2,3,4] and value to look for is '5', before method returns false high=3,ix=3,low=4. 'ix' thereby cannot be the index.

Howard  Dec 31, 2010 
Printed Page 122
Source listing for __contains__

Function never returns false and contains a python syntax error for 'ielif'. Need to check that the node exists and return false if it does not.

Anonymous  Sep 26, 2016 
Printed Page 147
Example 6-1, line 10

VerTexlist::begin() shouldn't take in any input. The book use VertexList::begin(u) which will not compile.

huy pham  Feb 01, 2011 
Other Digital Version 184
book is correct; downloaded source code has flaw

Line 135 of the provided source code for algs.model.searchtree.debug.DepthFirstSearch.java has an error on line 135:

return new Solution (initial, n, debug);

The code should be:

return new Solution (initial, successor, debug);

The consequence of this minor technical mistake is that the solution returned is missing the final move.

The corresponding line in the book is the third from the bottom (not counting blanks and closing brackets). It's correct there and in the algs.model.searchtree.DepthFirstSearch.

David H. Brown  May 07, 2015 
Printed Page 228, 229
228 bottom; 229 top

The confirmed errata correction is still needlessly confusing:

228 errata correction is: "Each edge (u,v) has a flow f(v,u) that defines the number of units of the commodity that flows from u to v."

In other words: 'f(to,from)'

The original text was more clear in using "f(u,v) == f(from,to)", but that conflicted with the notation semantic in the skew symmetry paragraph on 229.

The errata correction goes on to state:

Thus:
edge(s,v1).flow = 5
edge(s,v1).capacity = 10

Which reverses the sense of the corrected notation. The new rule states f(to,from), but the immediate usage is: edge(from,to). The new notation also makes the pseudo code in Figure 8-3 more confusing, along with the Java code.

This whole section needs a rewrite/proofread -- hopefully using the more intuitive (from,to) notation.

Anonymous  May 30, 2011 
Printed Page 229
3rd definition

CONFIRMED: wording change:

Skew Symmetry

Each edge (u,v) has a defined flow f(u,v). For mathematical
convenience, one can define for this edge that f(v,u) = -f(u,v). Doing
so enables network flow algorithms to add flows together when
determining the net flow from vertex u to v.

Nellie McKesson
Nellie McKesson
 
May 24, 2011 
PDF Page 260
Source code omission?

Where is c++ source code for Convex Hull ? Refernce in a README in the ADK for Installation.zip does not exist and there is no c++ code I have found.

Anonymous  Aug 24, 2015 
PDF Page 340+
all

I cannot find the index for this book, surprising, given that most books by this publisher have not forgotten this important part of any technical book.

Anonymous  Mar 25, 2011