并查集(Disjoint Set)
互不相交的数据集合。用一个代表元素来识别每个集合,这个元素属于这个集合。基本操作如下:
Make-Set:建立一个新的单元素集合
Find:判断元素在哪个集合中。可用于判断两个元素是都属于同一集合。
Union:把一个集合中的元素并入另一个集合中。
该数据结构可用于确定无向图的连通分量:对每个顶点make-set,遍历每一条边对每条边的两顶点的所在set进行union,最终得到的set的集合就是无向图的连通分量。
完整代码见:https://github.com/huangliu0909/Graph-Algorithms
使用栈(First-In-Last-Out),起始点入栈,当栈不为空时,pop,如果这个点未被访问,则标记为已访问,加入结果数组,将与这个点相连的顶点逐个入栈,循环直到栈为空。
完整排序算法代码:https://github.com/huangliu0909/Sort-Algorithms
快速排序是一种分治算法,不断找到pivot元素,将比它小的放在它左边,比它大的放在右边。双指针从头、从末尾分别开始与pivot比较,如果满足则移动,如果不满足则交换。
完整排序算法代码:https://github.com/huangliu0909/Sort-Algorithms
分治法,每次将一个数组均分成两部分,对这两部分进行merge。
“A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation (often a “less than or equal to” operator or a three-way comparison) that determines which of two elements should occur first in the final sorted list. The only requirement is that the operator forms a total preorder over the data, with:
if a ≤ b and b ≤ c then a ≤ c (transitivity)
for all a and b, a ≤ b or b ≤ a (connexity).”
From Wikipedia
“In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. “ From Wikipedia