Introduction to Algorithm
文章平均质量分 79
DickensTone
这个作者很懒,什么都没留下…
展开
-
Introduction to Algorithm 第二章第一节
2.1-2import java.util.Random;public class pro2 { public void insertionSort(int[] a) { int n = a.length; for(int i = 1; i < n; i++) { int key = a[i]; int j = i - 1; while(j >= ...原创 2018-06-30 11:46:27 · 253 阅读 · 0 评论 -
Introduction to Algorithm 第二章第二节
2-2.1n^3/1000 - 100n^2 - 100n + 3 忽略低阶项,和最重要的项的常系数。结果为Θ(n^3 )2-2.2给出算法的伪代码:SelectionSort(A)n = A.lengthfor i = 0 to n – 2 MIN = A[i] P = i for j =i + 1 to n – 1 ...原创 2018-07-03 15:25:10 · 258 阅读 · 0 评论 -
Introduction to Algorithm 第二章第三节
2.3-4 其中D(n)为分解问题成子问题所需要的时间C(n)为合并子问题的解成原问题的解 2.3-5伪代码Binary_Search(L, R, A, key) mid = (L + R) / 2 if(A[mid] == key) return mid if(L == R) return false if(A[mid...原创 2018-11-06 21:01:46 · 139 阅读 · 0 评论 -
Introduction to Algorithm Chapter 02 思考题
2-1a).插入排序对长度为k的排序时间为,有n/k部分,所以总的时间复杂度为 b).总共的层数为lg(n/k) + 1,每一层合并的复杂度为,所以总的时间复杂度为n*lg(n/k)c).d).2-2a).A'中的每一个元素都能在A中找到且两个数组中拥有相同的数量。b).我们先看代码: 1 for i = 1 to A.length - 12 ...原创 2019-01-10 22:12:00 · 192 阅读 · 0 评论