Swift algorithm club vs book

Whats the difference between the Data Structures & Algorithms in Swift book and the free available swift-algorithm-club? Thanks in advance

@appledeveloper Thanks very much for your question!

The Swift Algorithm Club contains all the contributions that we have as part of this project, and is extremely beneficial to anyone, and everyone. The book however has better diagrams, and walks the reader from the ground up to understand the data structures and algorithms, as well gradually build up the reader from simple data structures like LinkedLists to more complex ones like Graphs.

If you have some knowledge of Swift already, then the Algorithm Club should suffice. If you are a beginner to programming, then I would recommend the book :slight_smile:

I hope this helps!

All the best!

1 Like

Hello, I notice that the book uses struct for LinkedList, but Swift Algorithm Club uses class, why are they different and which one should I use in production? Thanks.

@kelvin_lau Can you please help with this when you get a chance? Thank you - much appreciated! :]

The reason we chose to declare the linked list as a struct was to keep the implementation consistent with other Swift standard library collection types - Array, Set, Dictionary. This means a few things:

  1. Methods that mutate the collection require the mutating keyword for structs. This is enforced by the compiler.
  2. Users of the LinkedList class will see the struct declaration instead of class. In Swift, structs are generally viewed to have value semantics, which we do implement for our LinkedList later in the chapter.

Classes generally convey reference semantics to the user. This isn’t the behaviour we wanted for our LinkedList.