# Data Structures & Algorithms in Swift

**URL:** https://forums.kodeco.com/c/books/data-structures-algorithms-swift/40.md

[Latest](https://forums.kodeco.com/latest.md) · [Categories](https://forums.kodeco.com/categories.md) · [Tags](https://forums.kodeco.com/tags.md)

---

## [Errata for Data Structures & Algorithms in Swift, 4th Edition](https://forums.kodeco.com/t/errata-for-data-structures-algorithms-in-swift-4th-edition/148023)

<div class="topic-metadata">

**Author:** [@jellodiil](https://forums.kodeco.com/u/jellodiil)\
**Replies:** 16\
**Last updated:** [October 12, 2022, 7:01pm UTC](https://forums.kodeco.com/t/errata-for-data-structures-algorithms-in-swift-4th-edition/148023 "2022-10-12T19:01:42Z")

</div>

Creating this topic to catch any typos and bugs in the 4th Edition of Data Structures & Algorithms in Swift.

---

## [About the Data Structures & Algorithms in Swift category](https://forums.kodeco.com/t/about-the-data-structures-algorithms-in-swift-category/41393)

<div class="topic-metadata">

**Author:** [@chrisrazeware](https://forums.kodeco.com/u/chrisrazeware)\
**Replies:** 1\
**Last updated:** [April 6, 2020, 5:08pm UTC](https://forums.kodeco.com/t/about-the-data-structures-algorithms-in-swift-category/41393 "2020-04-06T17:08:14Z")

</div>

For any and all discussion on the Data Structures & Algorithms in Swift book.

---

## [Are there any members of the team reading this forum?](https://forums.kodeco.com/t/are-there-any-members-of-the-team-reading-this-forum/211616)

<div class="topic-metadata">

**Author:** [@exchessplayerh](https://forums.kodeco.com/u/exchessplayerh)\
**Replies:** 4\
**Last updated:** [September 15, 2025, 1:54pm UTC](https://forums.kodeco.com/t/are-there-any-members-of-the-team-reading-this-forum/211616 "2025-09-15T13:54:03Z")

</div>

There have been some mentions about errata and other problems, yet there are barely any responses from the members of the team. It is kind of offensive, given the fact that books are not free, and there are problems (see…

---

## [Inserting a Node into a LinkedList Questions](https://forums.kodeco.com/t/inserting-a-node-into-a-linkedlist-questions/42151)

<div class="topic-metadata">

**Author:** [@psyaryu](https://forums.kodeco.com/u/psyaryu)\
**Replies:** 4\
**Last updated:** [August 25, 2025, 11:55pm UTC](https://forums.kodeco.com/t/inserting-a-node-into-a-linkedlist-questions/42151 "2025-08-25T23:55:43Z")

</div>

I have read through the book entirely with out doing any of the coding examples and now I am re-reading the content with doing the examples. Upon reaching the LinkedList section we can view the insert function: @discar…

---

## [Errata for Data Structures & Algorithms in Swift, 5th Edition](https://forums.kodeco.com/t/errata-for-data-structures-algorithms-in-swift-5th-edition/209429)

<div class="topic-metadata">

**Author:** [@jellodiil](https://forums.kodeco.com/u/jellodiil)\
**Replies:** 7\
**Last updated:** [July 9, 2025, 6:45am UTC](https://forums.kodeco.com/t/errata-for-data-structures-algorithms-in-swift-5th-edition/209429 "2025-07-09T06:45:12Z")

</div>

Creating this topic to catch any typos and bugs in the 5th Edition of Data Structures & Algorithms in Swift.

---

## [Chapter 6 Linked Lists: Conformance to collection, subscript method seems problematic with a force unwrap](https://forums.kodeco.com/t/chapter-6-linked-lists-conformance-to-collection-subscript-method-seems-problematic-with-a-force-unwrap/205192)

<div class="topic-metadata">

**Author:** [@chaugen55](https://forums.kodeco.com/u/chaugen55)\
**Replies:** 2\
**Last updated:** [July 3, 2025, 11:52am UTC](https://forums.kodeco.com/t/chapter-6-linked-lists-conformance-to-collection-subscript-method-seems-problematic-with-a-force-unwrap/205192 "2025-07-03T11:52:09Z")

</div>

In chapter 6, the authors propose a great solution to make LinkedList conform to the Collection protocol. This makes perfect sense to use a linked list with a familiar set of APIs. I have a concern though regarding the…

---

## [Download 5th edition PDF file?](https://forums.kodeco.com/t/download-5th-edition-pdf-file/210035)

<div class="topic-metadata">

**Author:** [@diuming](https://forums.kodeco.com/u/diuming)\
**Replies:** 8\
**Last updated:** [June 17, 2025, 3:08pm UTC](https://forums.kodeco.com/t/download-5th-edition-pdf-file/210035 "2025-06-17T15:08:35Z")

</div>

The book “Data Structures & Algorithms in Swift” is updated. I can read it on web but cannot download pdf file, why?

---

## [An error in LinkedList implementation in Chapter 6](https://forums.kodeco.com/t/an-error-in-linkedlist-implementation-in-chapter-6/198926)

<div class="topic-metadata">

**Author:** [@exchessplayerh](https://forums.kodeco.com/u/exchessplayerh)\
**Replies:** 0\
**Last updated:** [November 6, 2023, 5:27pm UTC](https://forums.kodeco.com/t/an-error-in-linkedlist-implementation-in-chapter-6/198926 "2023-11-06T17:27:37Z")

</div>

The function copyNodes(returningCopyOf node: Node\<Value\>?) should return the node itself, not nil when copy is not performed. Otherwise, the node is not removed from the list. The insertion function, should use copyNode…

---

## [Chapter 9, Challenge 5: Double-ended Queue](https://forums.kodeco.com/t/chapter-9-challenge-5-double-ended-queue/190618)

<div class="topic-metadata">

**Author:** [@tortely](https://forums.kodeco.com/u/tortely)\
**Replies:** 0\
**Last updated:** [August 21, 2023, 7:06am UTC](https://forums.kodeco.com/t/chapter-9-challenge-5-double-ended-queue/190618 "2023-08-21T07:06:14Z")

</div>

Protocol Deque is written for a struct, but DequeDoubleLinkedList is written as a class. The protocol appears as a struct in the 4th edition of the online book and the github repo. protocol Deque { associatedtype E…

---

## [Removing a node after a particular node fails after COW fix](https://forums.kodeco.com/t/removing-a-node-after-a-particular-node-fails-after-cow-fix/54904)

<div class="topic-metadata">

**Author:** [@pauladdy](https://forums.kodeco.com/u/pauladdy)\
**Replies:** 14\
**Last updated:** [August 19, 2023, 3:55am UTC](https://forums.kodeco.com/t/removing-a-node-after-a-particular-node-fails-after-cow-fix/54904 "2023-08-19T03:55:43Z")

</div>

In the linked list section, I think I’ve found bug for the “remove(after:)” func after we implement the “copyNodes()” function. Before we add copyNodes(), the function works adequately, and we have “After removing at in…

---

## [Queue Stack Problem](https://forums.kodeco.com/t/queue-stack-problem/185726)

<div class="topic-metadata">

**Author:** [@jsh0976](https://forums.kodeco.com/u/jsh0976)\
**Replies:** 0\
**Last updated:** [March 30, 2023, 1:06pm UTC](https://forums.kodeco.com/t/queue-stack-problem/185726 "2023-03-30T13:06:11Z")

</div>

Queue Stack Github storage has a something problem. There is no code. plz. check the GitHub repo Thanks.

---

## [Chapter 7 LinkedList Challenges 5th problem has a more elegant solution](https://forums.kodeco.com/t/chapter-7-linkedlist-challenges-5th-problem-has-a-more-elegant-solution/183582)

<div class="topic-metadata">

**Author:** [@alyakan](https://forums.kodeco.com/u/alyakan)\
**Replies:** 0\
**Last updated:** [February 5, 2023, 9:40pm UTC](https://forums.kodeco.com/t/chapter-7-linkedlist-challenges-5th-problem-has-a-more-elegant-solution/183582 "2023-02-05T21:40:15Z")

</div>

First I wanted to say how much I appreciate this book as it sparked an interest in me for data structures and algorithms which I never knew I had! Anyway, I was able to figure out a nice solution for the 5th problem in …

---

## [Chatper 6: LinkedList COW optimization of sharing nodes also works for \`pop()\` operations](https://forums.kodeco.com/t/chatper-6-linkedlist-cow-optimization-of-sharing-nodes-also-works-for-pop-operations/183549)

<div class="topic-metadata">

**Author:** [@alyakan](https://forums.kodeco.com/u/alyakan)\
**Replies:** 0\
**Last updated:** [February 5, 2023, 12:50am UTC](https://forums.kodeco.com/t/chatper-6-linkedlist-cow-optimization-of-sharing-nodes-also-works-for-pop-operations/183549 "2023-02-05T00:50:34Z")

</div>

The book mentions the following at the very end of Chapter 6: The unidirectional nature of the linked list means that head-first insertions can ignore the “COW tax”! However, I believe this also applies to pop() oper…

---

## [DoublyLinkedList code weak reference](https://forums.kodeco.com/t/doublylinkedlist-code-weak-reference/182519)

<div class="topic-metadata">

**Author:** [@tchelyzt](https://forums.kodeco.com/u/tchelyzt)\
**Replies:** 2\
**Last updated:** [January 31, 2023, 11:54am UTC](https://forums.kodeco.com/t/doublylinkedlist-code-weak-reference/182519 "2023-01-31T11:54:40Z")

</div>

In your DoublyLinkedList code, you set prev and next to nil in the remove function. Would changing the class Node definition of previous to weak be equally valid? My code seems to work but I had to be careful. I had to …

---

## [Is this forum closed?](https://forums.kodeco.com/t/is-this-forum-closed/182779)

<div class="topic-metadata">

**Author:** [@tchelyzt](https://forums.kodeco.com/u/tchelyzt)\
**Replies:** 9\
**Last updated:** [January 20, 2023, 11:54pm UTC](https://forums.kodeco.com/t/is-this-forum-closed/182779 "2023-01-20T23:54:38Z")

</div>

Can’t see much action here? No moderators?

---

## [My LinkedLists (as written) can't contain optionals. How to make the compiler alert us?](https://forums.kodeco.com/t/my-linkedlists-as-written-cant-contain-optionals-how-to-make-the-compiler-alert-us/182562)

<div class="topic-metadata">

**Author:** [@tchelyzt](https://forums.kodeco.com/u/tchelyzt)\
**Replies:** 1\
**Last updated:** [January 16, 2023, 4:13pm UTC](https://forums.kodeco.com/t/my-linkedlists-as-written-cant-contain-optionals-how-to-make-the-compiler-alert-us/182562 "2023-01-16T16:13:56Z")

</div>

Question to be reformulated

---

## [In Linked Lists, why don't we have to write code to conform to Sequence?](https://forums.kodeco.com/t/in-linked-lists-why-dont-we-have-to-write-code-to-conform-to-sequence/182422)

<div class="topic-metadata">

**Author:** [@tchelyzt](https://forums.kodeco.com/u/tchelyzt)\
**Replies:** 0\
**Last updated:** [January 5, 2023, 3:25pm UTC](https://forums.kodeco.com/t/in-linked-lists-why-dont-we-have-to-write-code-to-conform-to-sequence/182422 "2023-01-05T15:25:35Z")

</div>

I’m making slow progress because I like to explore all ramifications of what I’m learning. Have been concentrating on Section II only and doing a lot of work on Linked Lists. It really bothered me that Nodes (an implemen…

---

## [Need help understanding the use of defer in the LinkedList pop() method](https://forums.kodeco.com/t/need-help-understanding-the-use-of-defer-in-the-linkedlist-pop-method/56175)

<div class="topic-metadata">

**Author:** [@vern\_vant](https://forums.kodeco.com/u/vern_vant)\
**Replies:** 5\
**Last updated:** [December 27, 2022, 4:27pm UTC](https://forums.kodeco.com/t/need-help-understanding-the-use-of-defer-in-the-linkedlist-pop-method/56175 "2022-12-27T16:27:33Z")

</div>

What is defer accomplishing in the pop method? @discardableResult public mutating func pop() -\> Value? { defer { head = head?.next if isEmpty { tail = nil } } return head?.value } Thanks for …

---

## [Heap Challenge 1 - Chapter 23](https://forums.kodeco.com/t/heap-challenge-1-chapter-23/81643)

<div class="topic-metadata">

**Author:** [@alif](https://forums.kodeco.com/u/alif)\
**Replies:** 3\
**Last updated:** [December 8, 2022, 6:54am UTC](https://forums.kodeco.com/t/heap-challenge-1-chapter-23/81643 "2022-12-08T06:54:30Z")

</div>

Cha Heap Data Structure Challenges Challenge 1: Write a function to find the nth smallest integer in an unsorted array. For example: let integers = \[3, 10, 18, 5, 21, 100\] n = 3 If n = 3, the result should be 10. \*…

---

## [LinkedList Index Comparable Conformance](https://forums.kodeco.com/t/linkedlist-index-comparable-conformance/180714)

<div class="topic-metadata">

**Author:** [@jonulak](https://forums.kodeco.com/u/jonulak)\
**Replies:** 1\
**Last updated:** [November 19, 2022, 4:41pm UTC](https://forums.kodeco.com/t/linkedlist-index-comparable-conformance/180714 "2022-11-19T16:41:34Z")

</div>

static public func ==(lhs: Index, rhs: Index) → Bool { switch (lhs.node, rhs.node) { case let (left?, right?): return left.next === right.next case (nil, nil): return true default: return false } } For the ==…

---

## [LinkedList, conformance to Collection is flawed](https://forums.kodeco.com/t/linkedlist-conformance-to-collection-is-flawed/180441)

<div class="topic-metadata">

**Author:** [@lacm1993](https://forums.kodeco.com/u/lacm1993)\
**Replies:** 1\
**Last updated:** [October 29, 2022, 2:16am UTC](https://forums.kodeco.com/t/linkedlist-conformance-to-collection-is-flawed/180441 "2022-10-29T02:16:55Z")

</div>

After conforming to collection you get access to a reversed() method but if you try to use it (iterate through the sequence backwards with a for loop for example) it fails with the message: “Fatal error: Only Bidirection…

---

## [Stacks: Challenge 2 solution bug?](https://forums.kodeco.com/t/stacks-challenge-2-solution-bug/174547)

<div class="topic-metadata">

**Author:** [@ckoski18](https://forums.kodeco.com/u/ckoski18)\
**Replies:** 1\
**Last updated:** [October 19, 2022, 6:07am UTC](https://forums.kodeco.com/t/stacks-challenge-2-solution-bug/174547 "2022-10-19T06:07:37Z")

</div>

The provided solution is: for char in str { if char == "(" { myStack.push(char) } else if char == ")" { if myStack.isEmpty { return false } else { myStack.pop() } } …

---

## [A Question about DoubleLinkedList.remove(\_:)](https://forums.kodeco.com/t/a-question-about-doublelinkedlist-remove/177764)

<div class="topic-metadata">

**Author:** [@ys\_xs](https://forums.kodeco.com/u/ys_xs)\
**Replies:** 2\
**Last updated:** [October 12, 2022, 7:17pm UTC](https://forums.kodeco.com/t/a-question-about-doublelinkedlist-remove/177764 "2022-10-12T19:17:26Z")

</div>

In the method of removing nodes, After completing this operation: prev.next = next && next?.previous = prev it seems that the node has no more strong reference. At this time, the node should have been destroyed, but in…

---

## [Is this a typo in Space Complexity section example?](https://forums.kodeco.com/t/is-this-a-typo-in-space-complexity-section-example/177950)

<div class="topic-metadata">

**Author:** [@cabmeurer](https://forums.kodeco.com/u/cabmeurer)\
**Replies:** 3\
**Last updated:** [September 10, 2022, 1:22am UTC](https://forums.kodeco.com/t/is-this-a-typo-in-space-complexity-section-example/177950 "2022-09-10T01:22:17Z")

</div>

Hello, So I started reading through the Data Structures and Algorithms Book and noticed something that doesn’t seem to match the explanation. In the Space Complexity example, the optimization example has the following …

---

## [【7. Linked List Challenges】Solution to Challenge 5](https://forums.kodeco.com/t/7-linked-list-challenges-solution-to-challenge-5/177625)

<div class="topic-metadata">

**Author:** [@ys\_xs](https://forums.kodeco.com/u/ys_xs)\
**Replies:** 1\
**Last updated:** [September 2, 2022, 6:06pm UTC](https://forums.kodeco.com/t/7-linked-list-challenges-solution-to-challenge-5/177625 "2022-09-02T18:06:41Z")

</div>

The following is the solution in this book, need :point\_right:“current = prev?.next“ and then :point\_right:“continue” var prev = head var current = head?.next while let currentNode = current { guard currentNode.val…

---

## [How to make the Ring Buffer circular?](https://forums.kodeco.com/t/how-to-make-the-ring-buffer-circular/67034)

<div class="topic-metadata">

**Author:** [@tomn](https://forums.kodeco.com/u/tomn)\
**Replies:** 3\
**Last updated:** [September 2, 2022, 10:05am UTC](https://forums.kodeco.com/t/how-to-make-the-ring-buffer-circular/67034 "2022-09-02T10:05:22Z")

</div>

The chapter 8: Queues talks about Ring buffer implementation. Yet this buffer is not circular. It does not wrap around and it does not start from the beginning when full. How to make it circular?

---

## [Singly linked list vs doubly linked list implementation of queue](https://forums.kodeco.com/t/singly-linked-list-vs-doubly-linked-list-implementation-of-queue/152539)

<div class="topic-metadata">

**Author:** [@suragch](https://forums.kodeco.com/u/suragch)\
**Replies:** 2\
**Last updated:** [September 2, 2022, 3:35am UTC](https://forums.kodeco.com/t/singly-linked-list-vs-doubly-linked-list-implementation-of-queue/152539 "2022-09-02T03:35:20Z")

</div>

In the Queues chapter, one of the implementations used a doubly linked list. I curious why you chose a doubly linked list rather than the plain linked list that we studied in the previous chapter? It seems like a singly …

---

## [No clue what is going on in the collection protocol for Linked List extension page 61](https://forums.kodeco.com/t/no-clue-what-is-going-on-in-the-collection-protocol-for-linked-list-extension-page-61/73649)

<div class="topic-metadata">

**Author:** [@throwaway123](https://forums.kodeco.com/u/throwaway123)\
**Replies:** 3\
**Last updated:** [July 27, 2022, 6:44pm UTC](https://forums.kodeco.com/t/no-clue-what-is-going-on-in-the-collection-protocol-for-linked-list-extension-page-61/73649 "2022-07-27T18:44:34Z")

</div>

Can anyone explain what each line does? I’ve understood everything in this chapter so far except for this part. I’m genuinely lost.

---

## [A problem about a functions in 6.8 Optimizing COW](https://forums.kodeco.com/t/a-problem-about-a-functions-in-6-8-optimizing-cow/174798)

<div class="topic-metadata">

**Author:** [@ys\_xs](https://forums.kodeco.com/u/ys_xs)\
**Replies:** 1\
**Last updated:** [July 18, 2022, 11:42am UTC](https://forums.kodeco.com/t/a-problem-about-a-functions-in-6-8-optimizing-cow/174798 "2022-07-18T11:42:37Z")

</div>

A minor predicament hi～ I have a question. Why does this code in the article missing the sentence “tail = newNode” Copynodes() has, but copyNodes(returningCopyOf:) has not private mutating func copyNodes(returnin…

---

## [Stack Challenge #2 - Code Review!](https://forums.kodeco.com/t/stack-challenge-2-code-review/170989)

<div class="topic-metadata">

**Author:** [@marlhex](https://forums.kodeco.com/u/marlhex)\
**Replies:** 2\
**Last updated:** [July 7, 2022, 6:42pm UTC](https://forums.kodeco.com/t/stack-challenge-2-code-review/170989 "2022-07-07T18:42:19Z")

</div>

Can someone review if this code is valid as a solution? - The difference is that I’m not popping and I’m using 2 different counters. The time complexity is still linear O(n), right? + I’m still using stack methods. So ap…

[Next page](https://forums.kodeco.com/c/books/data-structures-algorithms-swift/40.md?page=1)
