随笔分类 - 数据结构和算法系列
摘要:磁盘的容量单位有M、G、T,其关系为 1T = 1000G、1G = 1000M, 如样例所示先输入磁盘的个数,再依次输入磁盘的容量大小,然后按照从小到大的顺序对磁盘容量进行排序并输出。 相同大小的先输入的先输出 输入 3 20M 1T 300G 输出 20M 300G 1T import sys
阅读全文
摘要:最大公约数 //更相减损法 def func(num1, num2): while True: if num1 > num2: num1 -= num2 elif num1 < num2: num2 -= num1 else: return num1 gcd(a, b) = gcd(b, a mod
阅读全文
摘要:```c /* quicksort.c Author: Zoro Date: 2019/11/8 function: 快速排序 QuickSort pivot partition */ #include void quickSort(int arr[], int L, int R) { int i = L; int j = R; int pivot = arr[(L + R) / 2]; whil
阅读全文
摘要:```c/*Insertion SortAuthor: ZoroDate: 2019/11/7function: 插入排序*/#include void insert(int arr[], int n) { int key = arr[n]; int i = n; while (arr[i-1] > key) { arr[i] = arr[i-1]; ...
阅读全文
摘要:```c /* Selection Sort Writed by Zoro Date: 2019/11/7 function:选择排序 3 7 4 2 6 1 3 1 4 2 6 7 3 1 4 2 6 7 3 1 2 4 6 7 1 2 3 4 6 7 */ #include int findMaxPos(int arr[], int n) { int max = arr[0]; int pos
阅读全文
摘要:```c/*bubble.cwrite by Zorodate: 2019/11/7function: 冒泡排序*/#include void bubble(int arr[], int n) { int i; int tmp; for (i = 0; i arr[i+1]) { tmp = arr[i]; arr[i] = arr[...
阅读全文
摘要:堆排序(heapsort) Heap Sort 1. Complete Binary Tree 2. parent children heapify n = i parent = (i 1) / 2 c1 = 2i + 1 c2 = 2i + 2 c include void swap(in
阅读全文
摘要:递归 递归都可以用循环实现,反之不一定 递归应用 : DFS 深度优先搜索、前中后序二叉树遍历等等 递归需要满足的三个条件 1 一个问题的解可以分解为几个子问题的解 2 这个问题与分解之后的子问题,除了数据规模不同,求解思路完全一样 3 存在递归终止条件 如何编写递归代码 写出递推公式,找到终止条件
阅读全文
摘要:```python #Topological Sort ''' 1 2 3 4 5 1 -> 2 -> 1 3 -> 1 4 -> 5 -> 3 ''' ''' visited = [1, 2, 3, 4, 5] ret = [1, 2, 3, 4, 5] ''' def travel(visited, d, ele): if ele in visited: return if ele in d:
阅读全文
摘要:|--P vs NP 多项式时间求解 vs 多项式时间验证 P --> polynomial time 多项式时间 O(1) O(logn) O(n) O(nlogn) O(n^2) O(n^3) O(n^4) NP --> nondeterministic polynomial |--NP Com
阅读全文
摘要:|--1.python实现 | 测试用例 思考如何使用快排算法实现
阅读全文