Group Group Group Group Group Group Group Group Group

Errata for Data Structures and Algorithms in Swift, 3rd Edition

The official errata thread for Data Structures and Algorithms, 3rd edition!

Loving the book so far, thank you!
Here are some corrections needed in Chapter 6, Linked List code on page 83:

private mutating func copyNodes(returningCopyOf node: Node?) -> Node? {
guard !isKnownUniquelyReferenced(&head) else {
return node // The book has a nil here, so appending to uniquely referenced lists does not work
}
guard var oldNode = head else {
return nil
}
head = Node(value: oldNode.value)
var newNode = head
var nodeCopy: Node?
while let nextOldNode = oldNode.next {
if oldNode === node {
nodeCopy = newNode
}
newNode!.next = Node(value: nextOldNode.value)
newNode = newNode!.next
oldNode = nextOldNode
}
tail = newNode // Updating the tail is missing in the book
return nodeCopy
}

2 Likes

I found the book to be minimally helpful. It had minimal insight and minimal explanations of the algorithms. It would have been better to have less examples and more detail. I mean just try too decipher this:
extension LinkedList {
mutating func reverse() {
tail = head // reassign head to tail position
var prev = head
var current = head?.next
prev?.next = nil

  while current != nil {
    let next = current?.next
    current?.next = prev
    prev = current
    current = next
  }
}

}

The naming system of the variables leaves a lot to be desired and is very confusing. I have 3 apps on the app store and have been doing IOS for 3 years. The video and articles are way more clearer on the website. This book feels rushed.

1 Like

@ingo69 Thank you for your feedback - much appreciated!

Some small issues I’ve found (will add to the list as I go through the book):

  • In the index of Section II, Stack is mentioned to be Chapter 4, but the title of that chapter (right on the next page) says Chapter 6. Also, in the Stack Operations part it says “If you had a tough time with the linked list concepts, you’ll be glad to know that stacks are comparatively trivial.” but the linked list now goes afterwards (I guess it was moved?)

  • Seems like in the .epub version a lot of lists have their last item be 1 instead of the correct numeration. For example:

    • In the “insert(after:) operations” of the Linked List chapter, “Using a while loop, you move…” starts with 1. instead of 2.
    • In removeLast operations of Linked List, “Since current is the last node…" should be item #4, not #1
  • It seems like in Xcode 12, source files in a playground are not able to “see” each other, so if you open the finished LinkedList.playground you’ll find in LinkedList.swift that it shows the error “Cannot find type ‘Node’ in scope” even if Node is marked as public in Node.swift.

  • The missing tail updating that @snehanshu already pointed out

1 Like

Possible error with print statement shared by @amberspades. Section 1 Chp 2.2