{"id":15038101,"url":"https://github.com/andyron/swift-algorithm-club-cn","last_synced_at":"2025-04-06T20:13:00.196Z","repository":{"id":38375631,"uuid":"101478931","full_name":"andyRon/swift-algorithm-club-cn","owner":"andyRon","description":"swift-algorithm-club的翻译。使用Swift学习算法和数据结构。","archived":false,"fork":false,"pushed_at":"2021-01-14T16:35:45.000Z","size":8639,"stargazers_count":415,"open_issues_count":4,"forks_count":69,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-06T20:12:46.237Z","etag":null,"topics":["algorithms","chinese","data-structure","swift","swift4"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andyRon.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-26T10:28:05.000Z","updated_at":"2025-03-30T01:56:13.000Z","dependencies_parsed_at":"2022-08-09T03:15:55.541Z","dependency_job_id":null,"html_url":"https://github.com/andyRon/swift-algorithm-club-cn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyRon%2Fswift-algorithm-club-cn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyRon%2Fswift-algorithm-club-cn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyRon%2Fswift-algorithm-club-cn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyRon%2Fswift-algorithm-club-cn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andyRon","download_url":"https://codeload.github.com/andyRon/swift-algorithm-club-cn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543593,"owners_count":20955865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","chinese","data-structure","swift","swift4"],"created_at":"2024-09-24T20:37:06.695Z","updated_at":"2025-04-06T20:13:00.176Z","avatar_url":"https://github.com/andyRon.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003e 本项目是我对[Swift Algorithm Club](https://github.com/raywenderlich/swift-algorithm-club)，边学习边翻译的项目。由于能力有限，如发现错误或翻译不妥，请指正，欢迎pull request。也欢迎有兴趣、有时间的小伙伴一起参与翻译和学习🤓。当然也欢迎加⭐️，🤩🤩🤩🤨🤪。\n\n\u003e [说明和翻译进度](Schedule.markdown)\n\n\n\n\n\n---------------------------------------------------------------\n以下是原项目的README.markdown翻译(⏳表示还未翻译)\n---------------------------------------------------------------\n\n\n\n![Swift算法俱乐部](Images/SwiftAlgorithm-410-transp.png)\n\n# 欢迎来到Swift算法俱乐部！\n\n在这里，你可以找到很多流行的算法和数据结构的具体实现，使用的是大家最喜欢的新语言Swift，并对他们的工作原理配有详细的解释。\n\n如果你是一个计算机学院的学生，为了考试想学习一下算法；又或者你是一个自学成才的程序员，想提高一下自身的理论姿势水平 —— 你真是来对地方了！\n\n这个项目的目的是 **解释各种算法的工作方式**。所以我们主要关注代码的清晰性和可读性，而不是为了产出一个可复用的库，让读者可以直接拖进自己的工程使用。换句话说，绝大多数的代码都是可以用于实际的项目中的，不过需要你根据自己的项目需求进行一些调整。\n\n所有的代码都是兼容 **Xcode 9** 以及 **Swift 4** 的。如果 Swift 有更新，我们也会及时跟进。\n\n\n😍 **欢迎提供建议和贡献！** 😍\n\n## 重要链接\n\n[什么是算法和数据结构？](What%20are%20Algorithms.markdown) ——  薄饼！\n\n[为什么要学习算法？](Why%20Algorithms.markdown) ——  还在担心这不是你的菜吗？请读一下这篇文章。\n\n[大O表示法](Big-O%20Notation.markdown) ——  我们经常会听到这样的话：“这个算法是 **O(n)** 的”。如果你不知道这是啥意思，请读读这篇文章。\n\n[算法设计技巧](Algorithm%20Design.markdown) ——  怎样设计自己的算法？\n\n欢迎参与贡献  ——  通过留下issue反馈，或者提交pull request。\n\n## 从哪开始？\n\n如果你之前没有接触过算法和数据结构，你可以从下面这些简单易懂的算法开始看起：\n\n- [栈](Stack/)\n- [队列](Queue/)\n- [插入排序](Insertion%20Sort/)\n- [二分搜索](Binary%20Search/) 和 [二分搜索树](Binary%20Search%20Tree/)\n- [归并排序](Merge%20Sort/)\n- [Boyer-Moore字符串搜索](Boyer-Moore-Horspool/)\n\n## 算法列表\n\n### 搜索算法\n\n- [线性搜索](Linear%20Search/)\t从数组中查找某个元素。\n- [二分搜索](Binary%20Search/)\t从已排序的数组中快速查找元素。\n- [统计出现次数](Count%20Occurrences/)\t统计某个值在数组中的出现次数。\n- [查找最大／最小值](Select%20Minimum%20Maximum)\t找到数组中的最大／最小值。\n- [第K大元素](Kth%20Largest%20Element/)\t找到数组中的第 **K** 大元素，例如中位数。\n- [选取样本](Selection%20Sampling/)\t随机地从集合中选取一些元素作为样本。\n- [并查集](Union-Find/)\t保持一些不相交的集合，帮助你快速合并它们。\n\n### 字符串搜索算法\n\n- [暴力字符串搜索算法](Brute-Force%20String%20Search/)\t一个简单粗暴的方法。\n- [Boyer-Moore算法](Boyer-Moore-Horspool/)\t一种高效的字符串子串搜索算法。它不需要对被搜索的字符串中的字符进行逐一比较，而是根据一个查找表跳过其中的某些部分。\n- [Knuth-Morris-Pratt(KMP)算法](Knuth-Morris-Pratt/)\t一种线性时间字符串算法，它获得字符串出现的已经给定模型字符串的索引。\n- [Rabin-Karp 算法]\t使用哈希的快速搜索\n- [最长公共子序列算法](Longest%20Common%20Subsequence/)\t找到两个字符串中的最长公共子序列。\n- [Z-Algorithm](Z-Algorithm/)\t在String中查找模式的所有实例，并返回模式在String中开始的索引。\n\n### 排序算法\n\n探究排序算法的工作原理是非常有趣的，但在实际的编码中，你几乎永远也不会需要自己编写排序算法，Swift 自带的 `sort()` 函数已经非常够用了，但如果你还是好奇背后的原理，请继续阅读。\n\n基本的排序算法：\n\n- [插入排序](Insertion%20Sort/)\n- [选择排序](Selection%20Sort/)\n- [希尔排序](Shell%20Sort/)\n\n快速的排序算法：\n\n- [快速排序](Quicksort/)\n- [归并排序](Merge%20Sort/)\n- [堆排序](Heap%20Sort/)\n\n混合排序算法：\n- [内省排序](Introsort/)\n\n特殊的排序算法\n\n- [计数排序](Counting%20Sort/)\n- [基数排序](Radix%20Sort/)\n- [拓扑排序](Topological%20Sort/)\n\n不好的排序算法（知道就行了，不要用！）：\n\n- [冒泡排序](Bubble%20Sort/)\n- [慢排序](Slow%20Sort/)\n\n### 压缩算法\n\n- [变动长度编码法(RLE)](Run-Length%20Encoding/)\t将重复的值存储为一个单字节及其计数。\n- [哈夫曼编码](Huffman%20Coding/)\t将常见的元素使用更小的单位存储。\n\n### 杂项\n\n- [洗牌算法](Shuffle/)\t随机搅乱数组中的内容。\n- [梳排序](Comb%20Sort/)\t冒泡排序算法的改进。\n- [凸包算法](Convex%20Hull/)\n- [Miller-Rabin素性检测](Miller-Rabin%20Primality%20Test/). Is the number a prime number?\n- [MinimumCoinChange](MinimumCoinChange/). A showcase for dynamic programming.\n\n### 数学算法\n\n- [最大公约数算法(GCD)](GCD/) —— 特殊福利：最小公倍数算法。\n- [排列组合算法](Combinatorics/) —— 还记得高中学过俄组合数学吗？\n- [调度场算法](Shunting%20Yard/) —— 用于将中缀表达式转换为后缀表达式的经典算法。\n- [karatsuba乘法](Karatsuba%20Multiplication/). Another take on elementary multiplication.\n- [Haversine Distance](HaversineDistance/). Calculating the distance between 2 points from a sphere.\n- [⏳Strassen's Multiplication Matrix](Strassen%20Matrix%20Multiplication/). Efficient way to handle matrix multiplication.\n\n### 机器学习\n\n- [k-Means 聚类算法](K-Means/) —— 无监督的分类器，将数据聚类为 K 个簇。\n- ⏳K-近邻算法\n- [⏳线性回归](Linear%20Regression/). A technique for creating a model of the relationship between two (or more) variable quantities.\n- ⏳逻辑回归\n- ⏳神经网络\n- ⏳网页排名算法\n- [⏳朴素贝叶斯分类器](Naive%20Bayes%20Classifier/)\n- [⏳模拟退火算法(Simulated Annealing，SA)](Simulated%20annealing/). Probabilistic technique for approximating the global maxima in a (often discrete) large search space.\n\n\n\n## 数据结构\n\n对于特定的任务，数据结构的选择需要基于以下几点考量。\n\n首先，你的数据是具有某种形态的，并且有一些必要的操作方法。如果你想基于关键字来查找对象，需要的是字典类型的数据结构；如果你的数据原生就是分层级的，就需要某种类型的树形结构；而如果你的数据是线性的，则你需要的是数据结构可能就是栈或队列等。\n\n其次，具体的选择还与你在实际使用中最常用的操作方法有关，因为不同的数据结构都对不同的操作方法做了优化。举例来说，如果你经常需要获取集合中的某些较为重要的元素，那么使用堆或优先队列就比普通的数组要好很多。\n\n绝大多数情况下，使用 Swift 内建的 `Array`、`Dictinary`、`Set` 就足够高效了，但某些时候，可能还是需要某些更合适的数据结构...\n\n### 数组变体\n\n- [二维数组](Array2D/) —— 固定尺寸的二维数组，可用于棋盘游戏。\n- [比特集](Bit%20Set/) —— **n** 位大小固定尺度的序列。\n- [固定大小数组](Fixed%20Size%20Array/) - 如果你确切的知道数据的大小，使用老式的固定长度的数组会更加高效。\n- [有序数组](Ordered%20Array/) —— 一个永远有序的数组。\n- [Rootish Array Stack](Rootish%20Array%20Stack/). A space and time efficient variation on Swift arrays.\n\n### 队列\n\n- [栈](Stack/) —— 后进先出！\n- [队列](Queue/) —— 先进先出！\n- [双端队列](Deque/)\n- [优先队列](Priority%20Queue) —— 一个保持最重要的元素总是在最前面的队列。\n- [有限优先队列](Bounded%20Priority%20Queue) —— 元素最大数受限制的优先队列。 :construction:\n- [环形缓冲区](Ring%20Buffer/) —— 一个语义上的固定大小的环形缓冲区，实际使用的是一维序列头尾相接实现。\n\n### 列表\n\n- [链表](Linked%20List/) —— 链接起来的数据序列。包含单向和双向链表。\n- [跳表](Skip-List/) —— 跳过列表是一种概率数据结构，具有与AVL/或红黑树相同的对数时间限制和效率，并提供了有效支持搜索和更新操作的巧妙折衷。\n\n### 树\n\n- [树](Tree/) —— 通用目的的树形结构。\n- [二叉树](Binary%20Tree/) —— 一种节点最多有两个子节点的树形结构。\n- [二叉搜索树(BST)](Binary%20Search%20Tree/) —— 以某种方式组织自己的节点的二叉树，以求较快的查询速度。\n- [AVL树](AVL%20Tree/) —— 一种通过旋转来维持平衡的二叉搜索树。 :construction:\n- [红黑树](Red-Black%20Tree/). A self balancing binary search tree.\n- [伸展树](Splay%20Tree/). A self balancing binary search tree that enables fast retrieval of recently updated elements.\n- [线索二叉树](Threaded%20Binary%20Tree/). A binary tree that maintains a few extra variables for cheap and fast in-order traversals.\n- [线段树](Segment%20Tree/) —— 能够快速地对某区间进行计算。\n  - [Lazy Propagation](https://github.com/raywenderlich/swift-algorithm-club/tree/master/Segment%20Tree/LazyPropagation)\n- ⏳k-d 树\n- [ST(稀疏表)算法](Sparse%20Table/). Another take on quickly computing a function over a portion of an array, but this time we'll make it even quicker!.\n- [堆](Heap/) —— 存储在一维数组中的二叉树，所以它不需要使用指针。很适合做为优先队列使用。\n- ⏳斐波那契堆\n- [字典树(Trie)](Trie/). A special type of tree used to store associative data structures.\n- [B 树](B-Tree/). A self-balancing search tree, in which nodes can have more than two children.\n- [四分树](QuadTree/). A tree with 4 children.\n- [八叉树](Octree/). A tree with 8 children.\n\n### 哈希\n\n- [哈希表](Hash%20Table/) —— 允许你通过一个关键词来存取数据。字典通常都是基于哈希表实现的。\n- ⏳哈希函数\n\n### 集合\n\n- [布隆过滤器](Bloom%20Filter/) —— 一个常量内存数据结构，用于概率性的检测某个元素是否在集合中。\n- [哈希集合](Hash%20Set/) —— 使用哈希表实现的集合。\n- [多重集](Multiset/). A set where the number of times an element is added matters. (Also known as a bag.)\n- [有序集](Ordered%20Set/) —— 很看重元素顺序的集合。\n\n### 图\n\n- [图](Graph/)\n- [广度优先搜索(BFS)](Breadth-First%20Search/)\n- [深度优先搜索(DFS)](Depth-First%20Search/)\n- [最短路径算法](Shortest%20Path%20%28Unweighted%29/) —— 作用对象为无权值树。\n- [单源最短路径算法](Single-Source%20Shortest%20Paths%20(Weighted)/)\n\n- [最小生成树(未加权图)](Minimum%20Spanning%20Tree%20%28Unweighted%29/) —— 作用对象为无权值树。\n- [最小生成树(加权图)](Minimum%20Spanning%20Tree/)\n\n- [任意两点间的最短路径算法](All-Pairs%20Shortest%20Paths/)\n- [迪杰斯特拉算法(Dijkstra's shortest path algorithm)](Dijkstra%20Algorithm/)\n\n## 智力题\n\n很多程序员在面试时都会被问到一些算法性质的智力题。这里只囊括了一点比较有趣的。想了解更多的智力题（及答案），请浏览[这里](http://elementsofprogramminginterviews.com/)，还有[这里](http://www.crackingthecodinginterview.com)。\n\n- [二和问题](Two-Sum%20Problem/)\n- [⏳Three-Sum/Four-Sum Problem](3Sum%20and%204Sum/)\n- [⏳Fizz Buzz](Fizz%20Buzz/)\n- [⏳蒙提霍尔问题](Monty%20Hall%20Problem/)\n- [⏳Finding Palindromes](Palindromes/)\n- [⏳Dining Philosophers](DiningPhilosophers/)\n- [⏳Egg Drop Problem](Egg%20Drop%20Problem/)\n- [⏳Encoding and Decoding Binary Tree](Encode%20and%20Decode%20Tree/)\n\n\n## 贡献者\n\nSwift算法俱乐部最初是由[Matthijs Hollemans](https://github.com/hollance) 创建。 \n\n现在主要是[Vincent Ngo](https://www.raywenderlich.com/u/jomoka) 和 [Kelvin Lau](https://github.com/kelvinlauKL) 维护。\n\nSwift算法俱乐部是来自[raywenderlich.com](https://www.raywenderlich.co)社区的[许多数算法成员](https://github.com/rwenderlich/swift-algorithm-club/graphs/contributors)的一起合作努力的成果。\n\n## 许可(License)\n\n所有内容均根据MIT开源许可条款获得许可。\n\n通过在此发布或通过此论坛提交任何pull request，即表示您同意您提交或创建的所有内容（包括代码和文本）均受此许可证的约束。 Razeware，LLC和其他人将拥有许可中描述的有关此内容的所有权利。 可以在[此处](https://github.com/raywenderlich/swift-algorithm-club/blob/master/LICENSE.txt)找到许可的准确条款。\n\n[![Build Status](https://travis-ci.org/raywenderlich/swift-algorithm-club.svg?branch=master)](https://travis-ci.org/raywenderlich/swift-algorithm-club)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyron%2Fswift-algorithm-club-cn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyron%2Fswift-algorithm-club-cn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyron%2Fswift-algorithm-club-cn/lists"}