Please post errors found in the published version of Grokking Algorithms here. We'll publish a comprehensive list for everyone's convenience. Thank you!

The calculation of mid = (low + high)/2 on page 8 is subject to overflow errors if low and high are > than (max value for the numeric type)/2..
The calculation should be low + (high - low)/2. On the page 9, mid is even more wrong since /2 is missing.

The top half of the page sets up the weights such that start -> A is 6 and start -> B is 2. However, the section at the middle of the page shows the weights being swapped:

on page 9, in the full code of the binary_search function, line 6 of the listing is missing the " / 2" to get the middle element, as shown in the example at the bottom of page 8.
i.e it should read "mid = (low + high) / 2", but instead only shows "mid = (low + high)"

In the epub and pdf versions, the Manning logos are lo-res in the front matter. The rat images in the front matter and chapter openers appear to be lo-res as well. Please check these elements across all platforms before reprint.

On the eBook, page 16 second line it says "it will take you 4 operations to draw a grid of 16 boxes (log 16 is 4)." It should be log2 (16) = 4 because log(16) =2.7

In the Hash Table Recap section on page 94 of the eBook and physical book, I see it recommends resizing the Hash Table when the load factor is .07. This should be .7. Resizing at .07 would be cray.

In my neophyte experience with computer programming, "state" [1] is one of those _big ideas_. The author said here that he spoke about it, but I can't find a specific reference using the term.

There are a few earlier references, but hardly definitive explanation to be "remembering".

44.3 "When you called the `greet2()` function, the `greet` function was `partially completed`. This is the big idea behind this section: _when you call a function from another function, the calling function is paused in a partially complete state_. All the values of the variables for that function are still stored in memory."

49.2 "The 'pile of boxes' is saved on the stack! This is a stack of half-completed function calls, wach with it's own half-complete list of boxes to look through. Using the stack is convenient because you don't have to keep track of a pile of boxes yourself--the stack does it for you.

In Chapter 9, page 173, the matrix at the top of the page, under matrix row #4, column #1 (the bottom left matrix entry) shows "$3500 I", it should show "$2000 I" instead.

These final two lines need to be indented such that they are within the while loop, otherwise you don't update your exit condition.
-----------------------
Pg 43

def greet2(name):
print "how are you, " + name + "?"
def bye():
print "ok bye!"

The second function needs to be de-dented to the same level as the first. As shown, the second function is defined within the greet2 function which means you could not call it outside of the greet2 function.
----------------------
Pg 59

In chapter 2 the author consistently delineates between a linked list (AKA 'list' as he later refers to them) and an array. Then in exercises 4.2/4.3 he asks about writing recursive functions for a list, however, his solutions are for arrays. It may be important to explain that in python a 'list' is not a linked list, but an array. The nomenclature here is confusing as I wrote my solutions for a linked list based on his previous terminology.

These errors should really be corrected at least immediately in the electronic versions of the book. It's hard to trust a book about algorithms when at the very beginning of the book there is a so obvious error like the one you did about the binary search.

Set-covering time table in Greedy Algorithms, page 152

Hello guys,
Thank you to Adita Y. Bhargava and you for this amazing book.

Here, I propose a kind of fix for the Big O time in the Set-Covering table showed in Page 152, for the Greedy Algorithm.
Should say 2^n, not n!

Also, could be nice to mention that the Power Set "formula" 2^n is a given (to be trusted). I assumed the reader had to figure out why it was 2^n but I couldn't, and thus I thought I wasn't understating anything.

1. Axis are Swapped in both graphs from page 74. Should say: X-Axis: List-Size, Y-Axis: Time
See attached image. I looked at several graphs of O(log n) and O(n) in google images to confirm this.

2. Reasoning behind insertions and deletions being O(1) for Lists .Page 30

Quote from page 30:

It’s worth mentioning that insertions and deletions are O(1) time only if you can instantly access the element to be deleted. It’s a common practice to keep track of the first and last items in a linked list, so it would take only O(1) time to delete those.

When I read this, I get to understand that deletions take O(1) because the Liked-List Data Structure keeps a record of the first and last item of the list...
But that's not really the reason. Keeping track of the first and last item of the list is not the precise point.

The strongest reason it takes O(1) is because EACH AND EVERY "slot" (each element of the list) keeps track of let's say, 2 "pointers", one link that points to the previous element and another link that points towards the next element. Therefore, when deleting (or inserting) an element it is only a matter of changing the pointers in the previous and next elements. As mentioned in page 29.
It doesn't take much more time, because changing pointers/links is quick, as opposed to re-arranging/moving/shifting some or all elements of an Array.

The answer to exercise 8.4 (which asks whether or not "Breadth-first search" is a greedy algorithm) says that BFS is a greedy algorithm, but since my answer was different, I tried to understand why is it greedy. I searched online but couldn't find any reference to "Breadth-first search" being considered a greedy algorithm.

What I found, however, is another algorithm matching the same initials, BFS, one that's called "Best-first search", and is what people refer to as being a greedy algorithm.

On page 93, under exercise item D, it reads "...For example, if your hash size is 10, and the string is "bag," the index is 3 + 2+ 17 % 10 = 22 % 10 = 2."

On page 3, in the “What you need to know” section, it says the examples in this book are written in Python.
However, the last line of that page states “…Otherwise, binary search returns null”.
That's incorrect because there's no null in Python.
Python has None, which is exactly what the binary search code returns on page 9.

537016 wrote:On page 93, under exercise item D, it reads "...For example, if your hash size is 10, and the string is "bag," the index is 3 + 2+ 17 % 10 = 22 % 10 = 2."

Shouldn't that read 3 + 2 + 17 = 22 % 10 = 2?

Thanks, loving the book so far.

-Carlos

Carlos,
I wrote it that way because `3 + 2 + 17 % 10 = 22 % 10`. `3 + 2 + 17 != 22 % 10` because the left hand side equals 22 and the right hand side equals 2. But it sounds like you understood the gist of what I was trying to say

AmrMostafa wrote:The answer to exercise 8.4 (which asks whether or not "Breadth-first search" is a greedy algorithm) says that BFS is a greedy algorithm, but since my answer was different, I tried to understand why is it greedy. I searched online but couldn't find any reference to "Breadth-first search" being considered a greedy algorithm.

What I found, however, is another algorithm matching the same initials, BFS, one that's called "Best-first search", and is what people refer to as being a greedy algorithm.