数据结构
冰糖葫芦没有冰糖
这个作者很懒,什么都没留下…
展开
-
2021-09-07 几种算法总结
广度优先搜索: 找出段数最少的路径,操作数最少 狄克斯特拉算法: 找出最快的路径,权重, 更新节点的开销,计算最小的总权重。【无负权边】 贝尔曼-福德算法: 找出最快的路径,权重, 更新节点的开销,计算最小的总权重。适用于包含负权边 贪婪算法: 求近似解; K最近邻算法:特征抽取; 二叉查找树 (binary search tree): 查找,插入,删除: log(n) 访问时间:log(n) 不可以随机访问; 常见数据结构:红黑树,B树,堆,伸展树 ...原创 2021-09-07 15:32:47 · 113 阅读 · 0 评论 -
快速排序
def quickSort(arr): if (len(arr) < 2): return arr else: array = arr[0] less = [i for i in arr[1:] if i <= array] lager = [i for i in arr[1:] if i > array] return quickSort(less) + [array] + quickSort原创 2021-09-06 17:31:46 · 66 阅读 · 0 评论 -
递归 递归数组求和
递归算法: 递归和循环在运行上没有太大区别,递归相对来说更容易理解; 递归需要两个条件: 基线条件:自己调用自己 递归条件:不再调用自己 def count(i): print(i) if i < 0: return else: count(i-1) ...原创 2021-09-06 16:05:29 · 175 阅读 · 0 评论 -
选择排序
def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if (arr[i] < smallest): smallest = arr[i] smallest_index = i return smallest_index def selectionSort(arr): newA原创 2021-09-06 15:35:02 · 62 阅读 · 0 评论 -
链表与数组
链表 1. 链表的每个元素都存储了下个元素的地址 2. 链表的随机读取效率没有数组高,需要先逐次访问第一个元素以获取第二个元素的地址,依次类推 3. 链表相对数组的优势在于插入数据,删除数据 对数组和链表的常见运行时间进行分析: 数组: 读取O(1) 插入读取O(n) 删除O(n) 链表: 读取O(n) 插入读取O(1) 删除O(1) 前提:立即访问或删除元素时 ...原创 2021-09-06 15:06:59 · 67 阅读 · 0 评论 -
常见大O 运行时间
不同的算法具有不同的操作数时间: 有常见的5种形式: log(n) n nlog(n) nn n! 以上操作的元素越多, 运行时间分别是log(n) 最快,n!最慢原创 2021-09-06 14:52:54 · 111 阅读 · 0 评论 -
递归函数 递归输出 设定终止条件 避免死循环
#include <iostream> using namespace std; void rePrint(int* a) { if (*a == 6) { return; } rePrint(a + 1); cout << *a << endl; } int main() { int a[6] = { 1, 2, 3, 4, 5, 6 }; rePrint(a); system("pause"); }原创 2021-08-22 23:27:20 · 657 阅读 · 0 评论 -
选择排序 升序
#include <iostream> using namespace std; int main() { int arr[5] = { 5,2,1,4,3 }; int(*p)[5] = &arr; for (int i = 0; i < 5; i++) { cout << (*p)[i]; } cout<< endl; int len = sizeof(arr) / sizeof(int); for (int i = 0; i原创 2021-08-22 22:34:18 · 127 阅读 · 0 评论 -
常见数组指针定义方式
#include <iostream> using namespace std; int main() { int arr[5] = { 1,2,3,4,5 }; int(*p)[5] = &arr; for (int i = 0; i < 5; i++) { cout << (*p)[i] << endl; } }原创 2021-08-22 22:18:43 · 88 阅读 · 0 评论