swift-algorithm-club README

The project's README from github.com/kodecocodes/swift-algorithm-club. As one markdown file: README.md.

Swift Algorithm Club

Welcome to the Swift Algorithm Club!

Here you'll find implementations of popular algorithms and data structures in everyone's favorite new language Swift, with detailed explanations of how they work.

If you're a computer science student who needs to learn this stuff for exams -- or if you're a self-taught programmer who wants to brush up on the theory behind your craft -- you've come to the right place!

The goal of this project is to explain how algorithms work. The focus is on clarity and readability of the code, not on making a reusable library that you can drop into your own projects. That said, most of the code should be ready for production use but you may need to tweak it to fit into your own codebase.

Code is compatible with Xcode 10 and Swift 4.2. We'll keep this updated with the latest version of Swift. If you're interested in a GitHub pages version of the repo, check out this.

:heart_eyes: Suggestions and contributions are welcome! :heart_eyes:

What are algorithms and data structures? Pancakes!

Why learn algorithms? Worried this isn't your cup of tea? Then read this.

Big-O notation. We often say things like, "This algorithm is O(n)." If you don't know what that means, read this first.

Algorithm design techniques. How do you create your own algorithms?

How to contribute. Report an issue to leave feedback, or submit a pull request.

Where to start?

If you're new to algorithms and data structures, here are a few good ones to start out with:

The algorithms

Searching

Sorting

It's fun to see how sorting algorithms work, but in practice you'll almost never have to provide your own sorting routines. Swift's own sort() is more than up to the job. But if you're curious, read on...

Basic sorts:

Fast sorts:

Hybrid sorts:

Special-purpose sorts:

Bad sorting algorithms (don't use these!):

Compression

Miscellaneous

Mathematics

Machine learning

Data structures

The choice of data structure for a particular task depends on a few things.

First, there is the shape of your data and the kinds of operations that you'll need to perform on it. If you want to look up objects by a key you need some kind of dictionary; if your data is hierarchical in nature you want a tree structure of some sort; if your data is sequential you want a stack or queue.

Second, it matters what particular operations you'll be performing most, as certain data structures are optimized for certain actions. For example, if you often need to find the most important object in a collection, then a heap or priority queue is more optimal than a plain array.

Most of the time using just the built-in Array, Dictionary, and Set types is sufficient, but sometimes you may want something more fancy...

Variations on arrays

Queues

Lists

Trees

Hashing

Sets

Graphs

Puzzles

A lot of software developer interview questions consist of algorithmic puzzles. Here is a small selection of fun ones. For more puzzles (with answers), see here and here.

Learn more!

Like what you see? Check out Data Structures & Algorithms in Swift, the official book by the Swift Algorithm Club team!

Data Structures & Algorithms in Swift Book

You’ll start with the fundamental structures of linked lists, queues and stacks, and see how to implement them in a highly Swift-like way. Move on to working with various types of trees, including general purpose trees, binary trees, AVL trees, binary search trees, and tries.

Go beyond bubble and insertion sort with better-performing algorithms, including mergesort, radix sort, heap sort, and quicksort. Learn how to construct directed, non-directed and weighted graphs to represent many real-world models, and traverse graphs and trees efficiently with breadth-first, depth-first, Dijkstra’s and Prim’s algorithms to solve problems such as finding the shortest path or lowest cost in a network.

By the end of this book, you’ll have hands-on experience solving common issues with data structures and algorithms — and you’ll be well on your way to developing your own efficient and useful implementations!

You can find the book on the raywenderlich.com store.

Credits

The Swift Algorithm Club was originally created by Matthijs Hollemans.

It is now maintained by Vincent Ngo, Kelvin Lau, and Richard Ash.

The Swift Algorithm Club is a collaborative effort from the most algorithmic members of the raywenderlich.com community. We're always looking for help - why not join the club? :]

License

All content is licensed under the terms of the MIT open source license.

By posting here, or by submitting any pull request through this forum, you agree that all content you submit or create, both code and text, is subject to this license. Razeware, LLC, and others will have all the rights described in the license regarding this content. The precise terms of this license may be found here.

Build Status

swift-algorithm-club (kodecocodes/swift-algorithm-club)

coding-interview
Searching Database…

What is this?Swift Algorithm Club is a community-maintained collection of implementations of popular algorithms and data structures written in Swift, each paired with a detailed explanation of how it works.
Is this a library I can drop into my app, or more of a learning reference?It's primarily a learning reference: the project explicitly prioritizes clear, readable code over building a reusable library, though most snippets can work in production with some tweaking.
How is the list organized, and where should a beginner start?Entries are grouped by topic — Searching, String Search, Sorting, Compression, Mathematics, Machine Learning, and Data Structures (arrays, queues, lists, trees, hashing, sets, graphs) — plus a Puzzles section of interview-style problems. For beginners it recommends starting with Stack, Queue, Insertion Sort, Binary Search/Binary Search Tree, Merge Sort, and Boyer-Moore string search.
Which Xcode and Swift version does the code target?The code is written for Xcode 10 and Swift 4.2, and the maintainers say they intend to keep it updated with newer Swift releases.
Is the code here production-ready as-is?Mostly yes, but not guaranteed out of the box — the authors say you may need to adapt a snippet to fit your own codebase since clarity, not reusability, was the design priority.
What is the companion book 'Data Structures & Algorithms in Swift'?It's an official paid book by the Swift Algorithm Club team, covering the same linked lists, trees, sorts, and graph algorithms with hands-on Swift implementations, available on the raywenderlich.com store.
Does it cover machine learning algorithms too?Yes, a dedicated Machine Learning section includes k-Means clustering, k-Nearest Neighbors, linear and logistic regression, neural networks, PageRank, Naive Bayes, and simulated annealing.
Are there interview-style practice problems?Yes, the Puzzles section covers classic coding-interview questions like Two-Sum, FizzBuzz, the Monty Hall Problem, Egg Drop, and the Dining Philosophers problem.
Size
13.8 MB
Stars
29.1K
Updated
CommitDec 06
Age
10y
Commits · 90 Days