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.
Version |
Location |
Description |
Submitted by |
Date submitted |
|
online ch 8
put function for separate chaining |
I was trying to follow the put and get functions for the Separate Chaining section of Chapter 8: Hashing, and I was confused that the put function only accepted a data arg.
Here's what i see in the text:
Next we need to define the put() and get() functions that will work with separate chaining. The put() function hashes the key and then attempts to store the data in the first cell of the chain at the hashed position. If that cell already has data in it, the function searches for the first open cell and stores the data in that cell. Here is the code for the put() function:
function put(data) {
var key = this.betterHash(data);
var index = 0;
if (this.table[key][index] == undefined) {
this.table[key][index] = data;
}
else {
while (this.table[key][index] !== undefined) {
++index;
}
this.table[key][index] = data;
}
}
However, the get function looks like this:
function get(key) {
var index = 0;
var pos = this.betterHash(key);
if (this.table[pos][index] == key) {
return this.table[pos][index+1];
}
else {
while (this.table[pos][index] != key) {
index += 2;
}
return this.table[pos][index+1];
}
return undefined;
}
Based on the get function and the description, shouldn't the put function look something like this?
var put = function(key, data) {
var pos = this.betterHash(key);
var index = 0;
if (typeof this.table[pos][0] === 'undefined') {
this.table[pos][0] = key;
this.table[pos][1] = data;
} else {
while (typeof this.table[pos][index] !== 'undefined') {
++index;
}
this.table[pos][index] = key;
this.table[pos][index+1] = data;
}
};
|
Jessica Chan |
Aug 28, 2014 |
Other Digital Version |
3
Chapter 3 example code |
In the example files:
we use these code to traverse the names List in chapter, but, the property 'pos' will alaways less than 'listSize', so there will be a endless loop..
for(names.front(); names.currPos() < names.length(); names.next()) {
print(names. getElement());
}
|
Anonymous |
Mar 27, 2015 |
Printed |
Page 3
print(x + y); |
print() statement is used in javascript.
|
Murty Ganti |
May 05, 2023 |
PDF |
Page 18
Creating New Arrays from Existing Arrays |
in the book:
var itDiv = cis.concat(dmp);
the correct would be:
var itDiv = cisDept.concat(dmpDept);
|
Anonymous |
Feb 20, 2015 |
Printed |
Page 18
last on the page |
Will never run because cis and dmp are undefined:
var cisDept = ["Mike", "Clayton", "Terrill", "Danny", "Jennifer"];
var dmpDept = ["Raymond", "Cynthia", "Bryan"];
var itDiv = cis.concat(dmp);
print(itDiv);
itDiv = dmp.concat(cisDept);
print(itDiv);
Looking forward to the 2nd edition where You are using node.js :-)
Thanks
|
Anonymous |
Jun 25, 2015 |
PDF |
Page 19
First line |
in the book:
itDiv = dmp.concat(cisDept);
correct would be:
itDiv = dmpDept.concat(cisDept);
|
Anonymous |
Feb 20, 2015 |
Printed |
Page 33
"Exercises" section |
Hi! I was just curious as to where the solutions to the end of chapter exercises would be posted. I tried looking at the Github for this book, but only the solutions to the end of chapter exercises aren't present. If I could be pointed in the right direction it would be greatly appreciated!
|
Anonymous |
Dec 02, 2021 |
Printed |
Page 41
function currPos() |
The last function for the ADT list , function currPos() is printed as follows:
function currPos() {
return pos;
}
i believe it should be as follows:
function currPos() {
return this.pos;
}
|
Anthony Poblacion |
Apr 13, 2016 |
Printed |
Page 43
Code Example |
'When the elements of the text file are split into the array, the newline character is placed with a space.'
This proves to be wrong as the following code snippet shows:
'a\nb'.split('\n') // ["a", "b"]
However it could make sense to trim the elements, to purify 'user input', but this would be another justification.
|
Anonymous |
Nov 06, 2015 |
PDF |
Page 43
1st line of code, just after list of movies |
var movies = read(films.txt).split("\n");
should read:
var movies = read("films.txt").split("\n");
There should be quotes around films.txt
|
Anonymous |
Aug 12, 2017 |
Printed |
Page 44
Last code example |
In the description above the code example it says: 'the function takes two arguments..' However the function takes four arguments finally. The two additional arguments are filmlist and customerList.
The first one is later in the function used as movielist, which is wrong. And the second one is used correctly inside the function but was declared on the same page further above as customers = new List().
Lot's of confusion here.
|
Anonymous |
Nov 06, 2015 |
ePub |
Page 45
3rd code example |
Explaining pop() and shift() return the values they remove, the 1st comment on the 2nd line should be 6, not 9.
|
Hanggjun Cho |
Aug 26, 2014 |
Printed |
Page 53
middle to end |
In the description of the algorithm, point 2, it says: 'Replace n with n/b'.
This should be: 'Replace n with the floored value of n / b'
Further down, in the JavaScript implementation of the algorithm, the value is correctly floored with Math.floor().
However, in this line a superfluous equal sign can be found, the whole line is:
num = Math.floor(num /= base);
num /= base divides num by base and assigns the value to num, which is then floored and assigned to num again. Much simpler would be:
num = Math.floor(num / base);
|
Anonymous |
Nov 07, 2015 |
Printed |
Page 57
Exercise 1 |
There cannot be one specific position of a missing parenthesis in an unbalanced arithmetic expression. This is possible only in a few cases.
"(a / b + c" could be corrected to "(a / b) + c" or "(a / b + c)", which would lead to different results.
Hence an algorithm can only be written that points to a beginning of a parenthesis which is not closed somewhere or an ending of a a parenthesis which is not opened somewhere.
|
Anonymous |
Nov 08, 2015 |
PDF |
Page 57
Iteration through a list |
// It takes the last element to the infinite loop
for(names.front(); names.currPos() < names.length(); names.next()) {
print(names.getElement());
}
as next() function never increments after the listSize()-1
function next(){
if(this.pos < this.listSize - 1){
++this.pos;
}
}
//Same for this
for(names.end(); names.currPos() >= 0; names.prev()) {
print(names.getElement());
}
//It never decrements the value after 0 so the loop never terminates
function prev(){
if(this.pos > 0){
--this.pos;
}
}
|
Prashant Yadav |
Feb 18, 2018 |
Printed |
Page 60
First code block |
names = [];
name.push("Cynthia");
names.push("Jennifer");
print(names); // displays Cynthia,Jennifer
-----
The second line should be `names.push`, not `name.push`; a missing "s".
|
Steven Vachon |
Nov 05, 2014 |
Printed |
Page 63
1st paragraph, 2nd sentence, 1st word |
"Once scenario we can simulate..."
should be
"One scenario we can simulate..."
where there is an unnecessary "c".
|
Steven Vachon |
Nov 05, 2014 |
Printed |
Page 68
4th paragraph, 4th sentence, 2nd word |
"We uses"
should be
"We use"
|
Steven Vachon |
Nov 05, 2014 |
Printed |
Page 70
2nd paragraph, 4th sentence |
"priority" instead of "priorty".
|
Anonymous |
Jun 21, 2015 |
PDF |
Page 73
Character 6 Linked Lists |
"since we can use the split() function without having to perform additional array element accesses."
It should be splice() not split, the split() method is method of String .
|
Anonymous |
Nov 07, 2015 |
Printed |
Page 76
5th paragraph, first sentence |
'To insert a node after an existing node, we first have to find the "after" node'
There technically is no "after" node as `null` comes after the head node to mark the end. The "after" node is the byproduct of our insertion. What we're looking for is the "before" node or, the existing node:
"To insert a node after an existing node, we first have to find that existing node" or similar.
|
Steven Vachon |
Nov 05, 2014 |
Printed |
Page 84
function insert |
The insert algorithm has an error, because it does not take care of the currNode.next.previous value - aka successor of the new node.
The successor of the new node should point back (previous value) to the new node:
newNode.next = current.next;
newNode.previous = current;
// this condition is true when the new node is not inserted
// at the end of the list
if (current.next) {
current.next.previous = newNode;
}
current.next = newNode;
|
Denise Nepraunig |
Dec 20, 2014 |
Printed |
Page 86
|
Nowhere is there an example of going backward through a circularly linked list. The `display()` function moves forward and simply moving forward from the last node to head and beyond is not equivalent to moving backward. I'm confused and can't seem to find much online (which is why I bought this book). Please help.
|
Steven Vachon |
Nov 05, 2014 |
Printed |
Page 90-94
various locations |
JavaScript does not have a `for each()`
This error occurs in 8 different locations.
|
Steven Vachon |
Nov 06, 2014 |
Printed |
Page 90-94
|
for each (var key in Object.keys(this.datastore)) {
print(key + " -> " + this.datastore[key]);
}
------
`for each...in` only works in Firefox as it's been deprecated along with the ES4/E4X draft spec. Simply switching to `for...in` won't work as it'd result in `print(0 + " -> " + this.datastore[0])`. It should look something like this:
Object.keys(this.datastore).forEach( function(key, index) {
print(key + " -> " + this.datastore[key]);
});
|
Steven Vachon |
Nov 06, 2014 |
Printed |
Page 91
|
There is no need to loop through the result of `Object.keys(this.datastore)` because it returns an Array which has a length.
This would be sufficient:
function count() {
return Object.keys(this.datastore).length;
}
|
Steven Vachon |
Nov 06, 2014 |
Printed |
Page 106
3rd code example |
"Here is a program to test the `put()` and `get()` functions:"
The code does not use `pnumbers.put()` anywhere.
|
Steven Vachon |
Nov 07, 2014 |
Printed |
Page 108
Example 8-5 |
`hTable.put(someNames[i])` is not setting `data` in `arguments[1]`. As a result, the `undefined` condition within `showDistro()` will always be `true`.
|
Steven Vachon |
Nov 10, 2014 |
Printed |
Page 108-109
put() and get() definitions |
You cannot put code between `if` and `else`. Additionally, your logic seems flawed.
- In `put()`, if the current index is undefined, set new data to the following index?
- In `get()`, why does it return data from the adjacent key? If just for the sake of returning data in cases of collision, you should explain the reasoning in the text. Also, why the `index += 2`? Also, `var hash` should be `var pos`.
Here is a jsFiddle of your code failing: http://jsfiddle.net/noyy41ur/
Perhaps this is what you were trying to do?: http://jsfiddle.net/noyy41ur/1/
|
Steven Vachon |
Nov 10, 2014 |
Printed |
Page 116
1st paragraph |
removed = "Alisa";
if ( names.remove("Mike")) {
print(removed + " removed.");
}
else {
print(removed + " not removed.");
}
Errata: -> again a request with "Mike" makes no sense.
----------
I assume, the author wanted to show a removal request with an object that isn't part of the set. Therefore, the code should be:
removed = "Alisa";
if ( names.remove(removed)) {
print(removed + " removed.");
}
else {
print(removed + " not removed.");
}
Alternatively, a code example like
if(names.remove("Alisa")......
would also make sense to show the effect.
|
Anonymous |
Jun 21, 2015 |
Printed |
Page 141
Code snippet below |
'The vertex class needs two data members. [...] These members are named label and wasVisited [...]'
In the Code example below the Vertex class constructor only sets the latter.
|
Anonymous |
Nov 11, 2015 |
Printed |
Page 145-149
the Codes parts |
all of the codes parts of BFS and DFS and find the shortest path do not works or give wrong results.
|
Hessnain Bakir |
Oct 29, 2015 |
PDF |
Page 149
[for each] section of the BFS code |
There is no this.edgeTo() function defined. Thought it was to call bfs recursively, tried, but didn't work on my code - had no time to review well:
for each(var w in this.adj[v]){
if(!this.marked[w]){
this.bfs(w);
}
}
|
Anthony Nandaa |
Nov 30, 2014 |
PDF |
Page 151
code example |
in function pathTo, path.push(s) should say path.push(source)
|
Alex Kaplan |
Jul 30, 2014 |
Printed |
Page 176
2nd paragraph |
In the description of mergesort it is stated that "It is customary, though not necessary, to implement Mergesort as a recursive algorithm. However, it is not possible to do so in JavaScript, as the recursion goes too deep for the language to handle."
This is flat-out wrong. Mergesort is a classic divide-and-conquer algorithm. For an array of length 2^N, the number of recursive calls on the call stack will be approximately N. Using a well implemented recursive mergesort, in order to reach a recursive depth exceeding the call stack size of virtually any JavaScript implementation, you would need to be operating on an array with something like 10^300 or more elements (and more like 10^6000 for many modern browser implementations).
It is very possible to implement a recursive mergesort, the language absolutely can handle it, and the recursion does not go too deep. A good example of a recursive mergesort implemented in JavaScript can be found here: http://www.nczonline.net/blog/2012/10/02/computer-science-and-javascript-merge-sort/
|
Eben Packwood |
Sep 05, 2014 |
Printed |
Page 191
Main figure |
Figure 13.1 should refer to min search, but in my edition I see the a figure related to the binary search.
|
Anonymous |
Mar 15, 2015 |
PDF |
Page 208
Figure 14-1. Recursion tree generated by recursive Fibonacci function |
The figure Figure 14-1. contains several misprints:
1. The leftmost node in the tree (to the right of under recurFib 3) should be recurFib 1 and not recurFib 5
2. recurFib 3 in the left part of the tree also contains the misprint where its left child node should be recurFib 2 and not recurFib 3.
|
Alexei Gorkov |
Apr 12, 2015 |