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)

Searching Database…

这是什么?Swift Algorithm Club 是一个由社区维护的合集,收录了用 Swift 编写的常见算法和数据结构的实现,每个实现都配有详细的原理说明。
这是可以直接放进我应用里使用的库,还是更偏向学习参考?它主要是一份学习参考。项目明确把代码的清晰易读放在首位,而不是打造可复用的库,不过大多数代码片段稍作调整后也能用于生产环境。
列表是怎么组织的?初学者应该从哪里开始?条目按主题分组,包括 Searching(搜索)、String Search(字符串搜索)、Sorting(排序)、Compression(压缩)、Mathematics(数学)、Machine Learning(机器学习),以及数据结构(数组、队列、链表、树、哈希、集合、图),另外还有一个收录面试式题目的 Puzzles(谜题)板块。对初学者,项目建议从 Stack、Queue、Insertion Sort、Binary Search/Binary Search Tree、Merge Sort 和 Boyer-Moore 字符串搜索开始学习。
这些代码针对的是哪个 Xcode 和 Swift 版本?代码基于 Xcode 10 和 Swift 4.2 编写,维护者表示打算随着新版 Swift 发布持续更新。
这里的代码能直接用于生产环境吗?基本可以,但不能保证开箱即用。作者表示,你可能需要根据自己的代码库调整代码片段,因为该项目的设计重点是清晰易懂,而不是可复用性。
配套书籍《Data Structures & Algorithms in Swift》是什么?这是 Swift Algorithm Club 团队官方出版的付费书籍,内容涵盖与项目相同的链表、树、排序和图算法,并提供可动手实践的 Swift 实现,可在 raywenderlich.com 商店购买。
也包含机器学习算法吗?包含。机器学习板块专门收录了 k-Means 聚类、k-Nearest Neighbors、线性回归和逻辑回归、神经网络、PageRank、朴素贝叶斯和模拟退火。
有面试风格的练习题吗?有。Puzzles 谜题板块收录了经典的编程面试题,例如 Two-Sum、FizzBuzz、Monty Hall Problem、Egg Drop 和 Dining Philosophers 问题。
Size
13.8 MB
Stars
29.1K
Updated
CommitDec 06
Age
10y
Commits · 90 Days