├── README.md ├── 第11章 近似算法 ├── 子集和问题.cpp ├── 求PI的近似值.cpp └── 装箱问题.cpp ├── 第12章 概率算法 ├── 主元素问题.cpp ├── 八皇后问题.cpp ├── 整数因子划分.cpp ├── 洗牌.cpp ├── 素数测试问题.cpp └── 随机快速排序.cpp ├── 第1章 算法设计基础 ├── 欧几里德算法求最大公约数.cpp └── 短除法求最大公约数.cpp ├── 第2章 算法分析基础 ├── 冒泡排序.cpp ├── 合并排序.cpp ├── 数组中求最小元素.cpp ├── 起泡排序的比较和移动次数.cpp └── 顺序查找.cpp ├── 第3章 蛮力法 ├── 串匹配BF算法.CPP ├── 串匹配KMP.CPP ├── 凸包问题.cpp ├── 最近点对.cpp ├── 百元买百鸡问题.cpp ├── 选择排序.cpp └── 顺序查找.cpp ├── 第4章 分治法 ├── Fibonacci序列.cpp ├── 归并排序.cpp ├── 快速排序.cpp ├── 数字旋转方阵.cpp ├── 最大字段和问题.cpp ├── 最近对问题.cpp ├── 棋盘覆盖问题.cpp └── 汉诺塔问题.cpp ├── 第5章 减治法 ├── 两个序列的中位数.cpp ├── 二叉查找树.cpp ├── 假币问题.cpp ├── 堆排序.cpp ├── 折半查找.cpp ├── 插入排序.cpp ├── 淘汰冠军问题.cpp └── 选择问题.cpp ├── 第6章 动态规划法 ├── 0-1背包问题.cpp ├── 多段图的最短路径问题.cpp ├── 多源点最短路径问题.cpp ├── 数塔问题.cpp ├── 最优二叉查找树.cpp ├── 最长公共子序列问题.cpp ├── 最长递增子序列.cpp └── 近似串匹配问题.cpp ├── 第7章 贪心法 ├── TSP最近邻点.cpp ├── 图着色问题.cpp ├── 埃及分数.cpp ├── 多机调度问题.cpp ├── 最小生成树PRIM.cpp ├── 活动安排问题.cpp └── 背包问题.cpp └── 第8章 回溯法 ├── 八皇后问题.cpp ├── 哈密顿回路.cpp ├── 图着色问题.cpp ├── 批处理作业调度.cpp └── 素数环.cpp /README.md: -------------------------------------------------------------------------------- 1 | # 算法设计与分析第二版源码 2 | 3 | ## [第1章 算法设计基础](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC1%E7%AB%A0%20%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E5%9F%BA%E7%A1%80) 4 | - [欧几里德算法求最大公约数](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC1%E7%AB%A0%20%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E5%9F%BA%E7%A1%80/%E6%AC%A7%E5%87%A0%E9%87%8C%E5%BE%B7%E7%AE%97%E6%B3%95%E6%B1%82%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0.cpp) 5 | - [短除法求最大公约数](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC1%E7%AB%A0%20%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E5%9F%BA%E7%A1%80/%E7%9F%AD%E9%99%A4%E6%B3%95%E6%B1%82%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0.cpp) 6 | ## [第2章 算法分析基础](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80) 7 | - [冒泡排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F.cpp) 8 | - [合并排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80/%E5%90%88%E5%B9%B6%E6%8E%92%E5%BA%8F.cpp) 9 | - [数组中求最小元素](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80/%E6%95%B0%E7%BB%84%E4%B8%AD%E6%B1%82%E6%9C%80%E5%B0%8F%E5%85%83%E7%B4%A0.cpp) 10 | - [起泡排序的比较和移动次数](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80/%E8%B5%B7%E6%B3%A1%E6%8E%92%E5%BA%8F%E7%9A%84%E6%AF%94%E8%BE%83%E5%92%8C%E7%A7%BB%E5%8A%A8%E6%AC%A1%E6%95%B0.cpp) 11 | - [顺序查找](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC2%E7%AB%A0%20%E7%AE%97%E6%B3%95%E5%88%86%E6%9E%90%E5%9F%BA%E7%A1%80/%E9%A1%BA%E5%BA%8F%E6%9F%A5%E6%89%BE.cpp) 12 | ## [第3章 蛮力法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95) 13 | - [串匹配BF算法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E4%B8%B2%E5%8C%B9%E9%85%8DBF%E7%AE%97%E6%B3%95.CPP) 14 | - [串匹配KMP](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E4%B8%B2%E5%8C%B9%E9%85%8DKMP.CPP) 15 | - [凸包问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E5%87%B8%E5%8C%85%E9%97%AE%E9%A2%98.cpp) 16 | - [最近点对](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E6%9C%80%E8%BF%91%E7%82%B9%E5%AF%B9.cpp) 17 | - [百元买百鸡问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E7%99%BE%E5%85%83%E4%B9%B0%E7%99%BE%E9%B8%A1%E9%97%AE%E9%A2%98.cpp) 18 | - [选择排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E9%80%89%E6%8B%A9%E6%8E%92%E5%BA%8F.cpp) 19 | - [顺序查找](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC3%E7%AB%A0%20%E8%9B%AE%E5%8A%9B%E6%B3%95/%E9%A1%BA%E5%BA%8F%E6%9F%A5%E6%89%BE.cpp) 20 | ## [第4章 分治法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95) 21 | - [Fibonacci序列](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/Fibonacci%E5%BA%8F%E5%88%97.cpp) 22 | - [归并排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E5%BD%92%E5%B9%B6%E6%8E%92%E5%BA%8F.cpp) 23 | - [快速排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F.cpp) 24 | - [数字旋转方阵](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E6%95%B0%E5%AD%97%E6%97%8B%E8%BD%AC%E6%96%B9%E9%98%B5.cpp) 25 | - [最大字段和问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E6%9C%80%E5%A4%A7%E5%AD%97%E6%AE%B5%E5%92%8C%E9%97%AE%E9%A2%98.cpp) 26 | - [最近对问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E6%9C%80%E8%BF%91%E5%AF%B9%E9%97%AE%E9%A2%98.cpp) 27 | - [棋盘覆盖问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E6%A3%8B%E7%9B%98%E8%A6%86%E7%9B%96%E9%97%AE%E9%A2%98.cpp) 28 | - [汉诺塔问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC4%E7%AB%A0%20%E5%88%86%E6%B2%BB%E6%B3%95/%E6%B1%89%E8%AF%BA%E5%A1%94%E9%97%AE%E9%A2%98.cpp) 29 | ## [第5章 减治法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95) 30 | - [两个序列的中位数](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E4%B8%A4%E4%B8%AA%E5%BA%8F%E5%88%97%E7%9A%84%E4%B8%AD%E4%BD%8D%E6%95%B0.cpp) 31 | - [二叉查找树](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91.cpp) 32 | - [假币问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E5%81%87%E5%B8%81%E9%97%AE%E9%A2%98.cpp) 33 | - [堆排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E5%A0%86%E6%8E%92%E5%BA%8F.cpp) 34 | - [折半查找](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E6%8A%98%E5%8D%8A%E6%9F%A5%E6%89%BE.cpp) 35 | - [插入排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F.cpp) 36 | - [淘汰冠军问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E6%B7%98%E6%B1%B0%E5%86%A0%E5%86%9B%E9%97%AE%E9%A2%98.cpp) 37 | - [选择问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC5%E7%AB%A0%20%E5%87%8F%E6%B2%BB%E6%B3%95/%E9%80%89%E6%8B%A9%E9%97%AE%E9%A2%98.cpp) 38 | ## [第6章 动态规划法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95) 39 | - [0-1背包问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/0-1%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98.cpp) 40 | - [多段图的最短路径问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E5%A4%9A%E6%AE%B5%E5%9B%BE%E7%9A%84%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84%E9%97%AE%E9%A2%98.cpp) 41 | - [多源点最短路径问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E5%A4%9A%E6%BA%90%E7%82%B9%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84%E9%97%AE%E9%A2%98.cpp) 42 | - [数塔问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E6%95%B0%E5%A1%94%E9%97%AE%E9%A2%98.cpp) 43 | - [最优二叉查找树](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E6%9C%80%E4%BC%98%E4%BA%8C%E5%8F%89%E6%9F%A5%E6%89%BE%E6%A0%91.cpp) 44 | - [最长公共子序列问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E6%9C%80%E9%95%BF%E5%85%AC%E5%85%B1%E5%AD%90%E5%BA%8F%E5%88%97%E9%97%AE%E9%A2%98.cpp) 45 | - [最长递增子序列](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E6%9C%80%E9%95%BF%E9%80%92%E5%A2%9E%E5%AD%90%E5%BA%8F%E5%88%97.cpp) 46 | - [近似串匹配问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC6%E7%AB%A0%20%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E6%B3%95/%E8%BF%91%E4%BC%BC%E4%B8%B2%E5%8C%B9%E9%85%8D%E9%97%AE%E9%A2%98.cpp) 47 | ## [第7章 贪心法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95) 48 | - [TSP最近邻点](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/TSP%E6%9C%80%E8%BF%91%E9%82%BB%E7%82%B9.cpp) 49 | - [图着色问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E5%9B%BE%E7%9D%80%E8%89%B2%E9%97%AE%E9%A2%98.cpp) 50 | - [埃及分数](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E5%9F%83%E5%8F%8A%E5%88%86%E6%95%B0.cpp) 51 | - [多机调度问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E5%A4%9A%E6%9C%BA%E8%B0%83%E5%BA%A6%E9%97%AE%E9%A2%98.cpp) 52 | - [最小生成树PRIM](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91PRIM.cpp) 53 | - [活动安排问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E6%B4%BB%E5%8A%A8%E5%AE%89%E6%8E%92%E9%97%AE%E9%A2%98.cpp) 54 | - [背包问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC7%E7%AB%A0%20%E8%B4%AA%E5%BF%83%E6%B3%95/%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98.cpp) 55 | ## [第8章 回溯法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95) 56 | - [八皇后问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95/%E5%85%AB%E7%9A%87%E5%90%8E%E9%97%AE%E9%A2%98.cpp) 57 | - [哈密顿回路](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95/%E5%93%88%E5%AF%86%E9%A1%BF%E5%9B%9E%E8%B7%AF.cpp) 58 | - [图着色问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95/%E5%9B%BE%E7%9D%80%E8%89%B2%E9%97%AE%E9%A2%98.cpp) 59 | - [批处理作业调度](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95/%E6%89%B9%E5%A4%84%E7%90%86%E4%BD%9C%E4%B8%9A%E8%B0%83%E5%BA%A6.cpp) 60 | - [素数环](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC8%E7%AB%A0%20%E5%9B%9E%E6%BA%AF%E6%B3%95/%E7%B4%A0%E6%95%B0%E7%8E%AF.cpp) 61 | ## [第11章 近似算法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC11%E7%AB%A0%20%E8%BF%91%E4%BC%BC%E7%AE%97%E6%B3%95) 62 | - [子集和问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC11%E7%AB%A0%20%E8%BF%91%E4%BC%BC%E7%AE%97%E6%B3%95/%E5%AD%90%E9%9B%86%E5%92%8C%E9%97%AE%E9%A2%98.cpp) 63 | - [求PI的近似值](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC11%E7%AB%A0%20%E8%BF%91%E4%BC%BC%E7%AE%97%E6%B3%95/%E6%B1%82PI%E7%9A%84%E8%BF%91%E4%BC%BC%E5%80%BC.cpp) 64 | - [装箱问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC11%E7%AB%A0%20%E8%BF%91%E4%BC%BC%E7%AE%97%E6%B3%95/%E8%A3%85%E7%AE%B1%E9%97%AE%E9%A2%98.cpp) 65 | ## [第12章 概率算法](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/tree/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95) 66 | - [主元素问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E4%B8%BB%E5%85%83%E7%B4%A0%E9%97%AE%E9%A2%98.cpp) 67 | - [八皇后问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E5%85%AB%E7%9A%87%E5%90%8E%E9%97%AE%E9%A2%98.cpp) 68 | - [整数因子划分](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E6%95%B4%E6%95%B0%E5%9B%A0%E5%AD%90%E5%88%92%E5%88%86.cpp) 69 | - [洗牌](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E6%B4%97%E7%89%8C.cpp) 70 | - [素数测试问题](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E7%B4%A0%E6%95%B0%E6%B5%8B%E8%AF%95%E9%97%AE%E9%A2%98.cpp) 71 | - [随机快速排序](https://github.com/WadeStack/Design-and-Analysis-of-Algorithms/blob/master/%E7%AC%AC12%E7%AB%A0%20%E6%A6%82%E7%8E%87%E7%AE%97%E6%B3%95/%E9%9A%8F%E6%9C%BA%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F.cpp) 72 | -------------------------------------------------------------------------------- /第11章 近似算法/子集和问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第11章 近似算法/子集和问题.cpp -------------------------------------------------------------------------------- /第11章 近似算法/求PI的近似值.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第11章 近似算法/求PI的近似值.cpp -------------------------------------------------------------------------------- /第11章 近似算法/装箱问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第11章 近似算法/装箱问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/主元素问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/主元素问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/八皇后问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/八皇后问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/整数因子划分.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/整数因子划分.cpp -------------------------------------------------------------------------------- /第12章 概率算法/洗牌.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/洗牌.cpp -------------------------------------------------------------------------------- /第12章 概率算法/素数测试问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/素数测试问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/随机快速排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第12章 概率算法/随机快速排序.cpp -------------------------------------------------------------------------------- /第1章 算法设计基础/欧几里德算法求最大公约数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第1章 算法设计基础/欧几里德算法求最大公约数.cpp -------------------------------------------------------------------------------- /第1章 算法设计基础/短除法求最大公约数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第1章 算法设计基础/短除法求最大公约数.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/冒泡排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第2章 算法分析基础/冒泡排序.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/合并排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第2章 算法分析基础/合并排序.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/数组中求最小元素.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第2章 算法分析基础/数组中求最小元素.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/起泡排序的比较和移动次数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第2章 算法分析基础/起泡排序的比较和移动次数.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/顺序查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第2章 算法分析基础/顺序查找.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/串匹配BF算法.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/串匹配BF算法.CPP -------------------------------------------------------------------------------- /第3章 蛮力法/串匹配KMP.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/串匹配KMP.CPP -------------------------------------------------------------------------------- /第3章 蛮力法/凸包问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/凸包问题.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/最近点对.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/最近点对.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/百元买百鸡问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/百元买百鸡问题.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/选择排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/选择排序.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/顺序查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第3章 蛮力法/顺序查找.cpp -------------------------------------------------------------------------------- /第4章 分治法/Fibonacci序列.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Fib(int n); 4 | int fib(int n); 5 | int main() 6 | { 7 | 8 | int r=Fib(7); 9 | cout< 2 | using namespace std; 3 | const int N = 8; //假设求解8枚硬币问题 4 | int a[N] = {2, 2, 2, 2, 2, 1, 2, 2}; 5 | 6 | int Coin(int low, int high, int n); 7 | 8 | int main() 9 | { 10 | int i=Coin(0,7,8); 11 | cout<<"假币是第"< add2) //在第2组查找,下标范围low+num1~low+num1+num2-1 39 | return Coin(low + num1, low + num1 + num2 - 1, num2); 40 | else //在第3组查找,下标范围low+num1+num2~high 41 | Coin(low + num1 + num2, high, num3); 42 | } 43 | -------------------------------------------------------------------------------- /第5章 减治法/堆排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第5章 减治法/堆排序.cpp -------------------------------------------------------------------------------- /第5章 减治法/折半查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第5章 减治法/折半查找.cpp -------------------------------------------------------------------------------- /第5章 减治法/插入排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第5章 减治法/插入排序.cpp -------------------------------------------------------------------------------- /第5章 减治法/淘汰冠军问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第5章 减治法/淘汰冠军问题.cpp -------------------------------------------------------------------------------- /第5章 减治法/选择问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第5章 减治法/选择问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/0-1背包问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/0-1背包问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/多段图的最短路径问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/多段图的最短路径问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/多源点最短路径问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/多源点最短路径问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/数塔问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/数塔问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最优二叉查找树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/最优二叉查找树.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最长公共子序列问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/最长公共子序列问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最长递增子序列.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/最长递增子序列.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/近似串匹配问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第6章 动态规划法/近似串匹配问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/TSP最近邻点.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第7章 贪心法/TSP最近邻点.cpp -------------------------------------------------------------------------------- /第7章 贪心法/图着色问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第7章 贪心法/图着色问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/埃及分数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第7章 贪心法/埃及分数.cpp -------------------------------------------------------------------------------- /第7章 贪心法/多机调度问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/81e0d996f4983b4ad8b29e9585c263c120468d8c/第7章 贪心法/多机调度问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/最小生成树PRIM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int n = 6; 4 | const int MAX = 100; 5 | typedef struct 6 | { 7 | int lowcost; 8 | int adjvex; 9 | } Element; 10 | 11 | void Prim(int arc[n][n], int w); 12 | 13 | int main( ) 14 | { 15 | int arc[n][n] = {{MAX, 34, 46, MAX,MAX,19}, 16 | {34, MAX, MAX,MAX,12, MAX},{46, MAX, MAX, 17, MAX, 25}, 17 | {MAX, MAX, 17, MAX, 38, 25},{MAX, 12, 38, MAX, 26},{19, MAX, 25, 25, 26, MAX} 18 | }; 19 | Prim(arc, 0); 20 | return 0; 21 | } 22 | 23 | void Prim(int arc[n][n], int w) 24 | { 25 | int i, j, k; 26 | int min; 27 | Element shortEdge[10]; 28 | for (i = 0; i < n; i++) //初始化辅助数组shortEdge 29 | { 30 | shortEdge[i].lowcost = arc[w][i]; 31 | shortEdge[i].adjvex = w; 32 | } 33 | shortEdge[w].lowcost = 0; //将顶点0加入集合U 34 | for (i = 0; i < n - 1; i++) 35 | { 36 | for (min = 100, j = 0; j < n; j++) //寻找最短边的邻接点k 37 | { 38 | if((shortEdge[j].lowcost != 0) && (shortEdge[j].lowcost < min)) 39 | { 40 | min = shortEdge[j].lowcost; 41 | k = j; 42 | } 43 | } 44 | cout<