Errata, Chapter 1


p. 18
Printed: String b = 99;
Fixed: String b = "99";
Reported by Sami Losoi, 13-Dec-08.

p. 38
Printed: 10^6 not 100000 but 12
Fixed: 10^6 not 1000000 but 12
Reported by Swami Iyer, 19-Oct-07.

p. 44
Printed: 49.87
Fixed: 48.87
Reported by Kevin Wayne, 29-Jan-09.

p. 72, figure
Printed: 4th Hello 4th Hello 4th Hello
Fixed: 4th Hello 5th Hello 6th Hello
Reported by Sailesh Dhungana, 21-Oct-07.

p. 73, figure
Printed: EightHellos, DivisorsPattern, Newton, Factor
Fixed: TenHellos,   DivisorPattern,  Sqrt,   Factors
Reported by Swami Iyer, 3-Oct-07.

p. 77, Exercise 1.3.2
Printed: Program 1.3.3
Fixed: Program 1.2.3
Reported by William C. Nguyen, 26-Sep-07.

p. 79, Exercise 1.3.17
Printed: 1 - f(t) / f'(t)
Fixed: t - f(t) / f'(t)
Reported by Susanne Sherba, 30-Nov-07.

p. 84, Exercise 1.3.37
Printed: sin x = -x + x3/3! - x5/5! + ...
cos x = 1 + x2/2! - x4/4! + ...
Fixed: sin x = x - x3/3! + x5/5! - ...
cos x = 1 - x2/2! + x4/4! - ...
Reported by John Houlihan, 01-Aug-08.

p. 91
Printed: "2", "3", "4", "5", "6", "7", "8", "9", "10"  "Jack",  Queen", "King", "Ace"
Fixed: "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"
Reported by Michelle Lu and Jacob Hiller, 30-Sep-07.

p. 94, Program 1.4.1
Printed: perm[j] = t;
Fixed: perm[i] = t;
Reported by Thomas Kneeland, 28-Sep-07.

p. 95
Printed: the values of N and M are 16 and 5
Fixed: the values of N and M are 16 and 6
Reported by Michelle Lu, 30-Sep-07.

p. 100, Program 1.4.3
Printed: for (int i = 2; i < N; i++)
Fixed: for (int i = 2; i <=N; i++)
Reported by Hank Song, 19-Feb-08.

p. 100
Printed: % java PrimeSieve 17
Fixed: % java PrimeSieve 25
Reported by Swami Iyer, 27-Oct-07.

p. 104 and p. 106 figures
Printed: for (int j = 0; j < N; i++)
Fixed: for (int j = 0; j < N; j++)
Reported by Thomas Kneeland, 28-Sep-07.

p. 109
Printed:
if      (r < 0.25 && !a[x+1][y]) x++;
else if (r < 0.50 && !a[x-1][y]) x--;
else if (r < 0.75 && !a[x][y+1]) y++;
else if (r < 1.00 && !a[x][y-1]) y--;

Fixed: if      (r < 0.25) { if (!a[x+1][y]) x++; }
else if (r < 0.50) { if (!a[x-1][y]) x--; }
else if (r < 0.75) { if (!a[x][y+1]) y++; }
else if (r < 1.00) { if (!a[x][y-1]) y--; }
Reported by Greg Humphreys, 27-Jul-07.

p. 113, Exercise 1.4.7
Printed: System.out.println(i)
Fixed: System.out.println(a[i])
Reported by Matthias Makowsky, 19-Jun-08.

p. 116, Exercise 1.4.20
Printed: The value dist[i]
Fixed: The value dist[k]
Reported by Swami Iyer, 29-Oct-07.

p. 149
Printed: 4410000/44100
Fixed: 441000/44100
Reported by Andrea Brewer, 01-Oct-07.

p. 149
Printed: void double[] read(String file)
Fixed:      double[] read(String file)
Reported by Sailesh Dhungana, 22-Oct-07.

p. 164
Printed: multiply outDegree[i][j] by .90 / degree[i]
Fixed: multiply count[i][j] by .90 / outDegree[i]
Reported by Swami Iyer, 18-Oct-07.

p. 165, variable description box
Printed: outDegree[j]
Fixed: outDegree[i]
Reported by Swami Iyer, 18-Oct-07.

p. 165
Printed: StdOut.println(N + " " N)
Fixed: StdOut.println(N + " " + N)
Reported by Kevin Wayne, 18-Jun-07.

p. 171
Printed: (.02 * .02) + (.02 + .32) + (.32 * .02) + (.32 * .02) + (.32 * .47) = .17
Fixed: (.02 * .02) + (.02 + .38) + (.38 * .02) + (.38 * .02) + (.20 * .47) = .12
Reported by Swami Iyer, 16-Nov-07.



Errata, Chapter 2


p. 194
Printed: Φ(z) = φ(z) (z + z^3/3 + z^5 / 3*5 + z^5 / 3*5*7
Fixed: Φ(z) = 1/2 + φ(z) (z + z^3/3 + z^5 / 3*5 + z^7 / 3*5*7
Reported by Michelle Lu and Charles Karney, 03-Oct-07.

p. 198
Printed: we could change getCoupon()
Fixed: we could change uniform()
Reported by Michelle Lu, 05-Oct-07.

p. 211, Exercise 2.1.16
Printed: cos(d2) cos(d)
Fixed: cos(d2) cos(d1)
Reported by Charles Karney, 23-Oct-07.

p. 226
Printed: See Exercise 2.1.17
Fixed: See Exercise 2.1.28
Reported by Charles Karney, 18-Oct-07.

p. 227
Printed: the integers in the second column
Fixed: the numbers in the second column
Reported by Mario Lopez, 21-Aug-08.

p. 237
Printed: java StdStatistics< tiny.txt
Fixed: java StdStats< tiny.txt
Reported by Kevin Wayne, 1-Mar-09.

p. 238
Printed: plotPoints(), plotLine() , and plotBars()
Fixed: plotPoints(), plotLines(), and plotBars()
Reported by Mario Lopez, 21-Aug-08.

p. 243
Printed: Bernoulli Program (2.2.5)
Fixed: Bernoulli Program (2.2.6)
Reported by Mario Lopez, 22-Aug-08.

p. 260
Printed: is the same as the gcd of p and p % q
Fixed: is the same as the gcd of q and p % q
Reported by Susanne Sherba, 16-Jan-07.

p. 260, figure
Printed:
Fixed: gcd(192, 24) missing from figure
Reported by Fatu Conteh, 11-Oct-07.

p. 263, figure
Printed: Seventh line: moves(1,true)
Fixed: moves(1,false)
Reported by Katherine Song, 13-Mar-08.

p. 269, figure
Printed: sz point to half the length of a side of an H
Fixed: sz should be the full length of a side of an H
Reported by Kevin Wayne, 26-Feb-09.

p. 272
Printed: When 0 < H < 1/2 the displacements tend to decrease
When 2 > H > 1/2 displacements tend to increase
Fixed: When 0 < H < 1/2 the displacements tend to increase
When 2 > H > 1/2 the displacements tend to decrease
Reported by Mario Lopez, 22-Aug-08.

p. 273
Printed: not smaller the original
Fixed: not smaller than the original
Reported by Jayne Choi and Peter Toshev, 12-Oct-07.

p. 277
Printed: Are there situations when iteration
Fixed: Are there situations when recursion
Reported by Eric Finkelstein and Morgan Fowler, 06-Oct-07.

p. 278
Printed: public static int ex233(int n)
Fixed: public static void ex233(int n)
Reported by Susanne Sherba, 23-Jan-08.



Errata, Chapter 3


p. 321, Figure
Printed: c.potentialAt(x, y)
Fixed: c1.potentialAt(x, y)
Reported by Shotaro Makisumi, 03-Oct-08.

p. 350, Program 3.1.11
Printed: // Split file by column into M+1 files.
Fixed: // Split file by column into N files.
Reported by Shotaro Makisumi, 03-Oct-08.

p. 362, Program 3.1.1
Printed: Value of charges not specified.
Fixed: Assume value of charges is 1.0 for each Charge.
Reported by Donna Gabai, 03-Oct-07.

p. 368, Exercise 3.1.38
Printed: wrong rotation formula
Fixed: ti = (si - ci) cos(theta) - (sj - cj) sin(theta) + ci
tj = (si - ci) sin(theta) + (sj - cj) cos(theta) + cj
Reported by Joshua Gabai, 23-Mar-08.

p. 372, figure
Printed: public class Charge ()
Fixed: public class Charge
Reported by Kevin Wayne, 26-Mar-09.

p. 379
Printed: Program 3.2.2
Fixed: Add trailing } to main()
Reported by Kevin Wayne, 18-Jun-07.

p. 380
Printed: Its private draw() method scales
Fixed: Its draw() method scales
Reported by Shotaro Makisumi, 04-Oct-08.

p. 381
Printed: Program 3.2.3
Fixed: Better style: remove call to draw() in addDataPoint().
Reported by Kevin Wayne, 18-Jun-07.

p. 381, Program 3.2.3
Printed: private void draw()
Fixed: public void draw()
Reported by Shotaro Makisumi, 04-Oct-08.

p. 383
Printed: adds the step size times the sine ... step size times the cosine
Fixed: adds the step size times the cosine ... step size times the sine
Reported by Shiv Mohan Dutt, 29-Oct-08.

p. 385
Printed: turn right 60 degrees (left -120 degrees)
Fixed: turn right 120 degrees (left -120 degrees)
Reported by Shiv Mohan Dutt, 29-Oct-08.

p. 421
Printed: theta = atan(re / im)
Fixed: theta = Math.atan2(im, re)
Reported by Charles Karney, 18-Oct-07.

p. 421
Printed: b.im
Fixed: b.im()
Reported by Charles Karney, 14-Nov-07.

p. 434
Printed: if a is less than b, then b must be less than a
Fixed: if a is less than b, then b must be greater than a
Reported by Kareem Elnahal, 17-Nov-07.

p. 436
Printed: public Counter implements
Fixed: public class Counter implements
Reported by Mario Lopez, 26-Aug-08.

p. 437
Printed: "integrate(Gaussian.phi(), a, b)
Fixed: "integrate(Gaussian.phi(), a, b, N)
Reported by Charles Karney, 14-Nov-07.

p. 443
Printed: (x0-y0)^2 + (x0-y0)^2 + ...
Fixed: (x0-y0)^2 + (x1-y1)^2 + ...
Reported by Swami Iyer, 23-Nov-07.

p. 451, Exercise 3.3.12
Printed: two-dimensional vectors
Fixed: two-dimensional unit vectors
Reported by Charles Karney, 18-Oct-07.

p. 457
Printed: Vector (Program 3.3.4)
Fixed: Vector (Program 3.3.3)
Reported by Maia Ginsburg, 03-Jan-08.

p. 458
Printed: Body (Program 3.4.5)
Fixed: Vector (Program 3.4.1)
Reported by Maia Ginsburg, 03-Jan-08.



Errata, Chapter 4


p. 431
Printed: As with Complex paragraph
Fixed: rewrite to correct grammar
Reported by Barry Dewitt, 26-Jun-08.

p. 434
Printed: if a is less than b, then b must be less than a
Fixed: if a is less than b, then b must be greater than a
Reported by Doug Clark, 11-Nov-08.

p. 485, table
Printed: logarithmic 1000
Fixed: remove row corrresponding to logarithmic
Reported by Michelle Lu, 19-Oct-07.

p. 490-491
Printed: Charge object uses 20 bytes and Complex object uses 16 bytes
Fixed: Charge objects uses 32 bytes and Complex object uses 24 bytes
Reported by Donna Gabai, 06-Oct-07.

p. 493, table
Printed: 8N^2 + 20N + 16 and 16N^2 + 20N + 16
Fixed: 4N^2 + 20N + 16 and 8N^2 + 20N + 16
Reported by Donna Gabai, 11-Oct-07.

p. 501, Exercise 4.1.10
Printed: 5 seconds, 20 seconds, 45 seconds, 80 seconds, 125 seconds
Fixed: 5 seconds, 20 seconds, 45 seconds, 80 seconds
Reported by Donna Gabai, 06-Oct-07.

p. 515, Program 4.2.2
Printed: void (twice)
Fixed: double
Reported by Kevin Wayne, 20-Nov-07.

p. 515, Program 4.2.2
Printed: m (twice)
Fixed: mid
Reported by Kevin Wayne, 20-Nov-07.

p. 515
Printed: Test whether Φ(m) < y
Fixed: Test whether Φ(m) > y
Reported by Kareem Elnahal, 19-Oct-07.

p. 527, mergesort trace
Printed: was was but but was was was but
Fixed: was was was was was was was was
Reported by Donna Gabai, 31-Mar-08. p. 528, mergesort
Printed: % java Mergesort 8
Fixed: % java Mergesort < tiny.txt
Reported by Kevin Wayne, 28-Febr-09.

p. 563
Printed: if (N == a.length/4) resize(a.length/2);
Fixed: if (N > 0 && N == a.length/4) resize(a.length/2);
Reported by Kevin Wayne, 13-Feb-08.

p. 587
Printed: iterate from i = 0 to N-1 (FIFO order)
private int i = 0;
public boolean hasNext() { return i < N;  }
public Item next()       { return a[i++]; }
Fixed: iterate from i = N-1 to 0 (LIFO order)
private int i = N;
public boolean hasNext() { return i > 0;  }
public Item next()       { return a[--i]; }
Reported by Kareem Elnahal, 26-Nov-07.

pp. 622, 623, 624, 626
Printed: of appears before it alphabetically
Fixed: replace of with if
Reported by Greg Humpreys, 31-Oct-07.

p. 624
Printed: if the search ley is less, we set the right link
Fixed: if the search ley is greater, we set the right link
Reported by Robert Zahler, 01-Dec-07.

p. 633
Printed: the item type should implement the Comparable interface
Fixed: the key type should implement the Comparable interface
Reported by Doug Clark, 13-Nov-08.

p. 635
Printed: ST on the booksite uses java.util.TreeSet
Fixed: SET on the booksite uses java.util.TreeSet
Reported by Robert Zahler, 01-Dec-07.

p. 665, Program 4.5.3
Printed: delimeter
Fixed: delimiter
Reported by Seth Priebatsch, 25-Nov-07.