【CLRS】《算法导论》读书笔记(四):栈(Stack)、队列(Queue)和链表(Linked List)
摘要:栈(Stack)维基百科:http://en.wikipedia.org/wiki/Stack_(abstract_data_type)在栈中,被删除的是最近插入的元素:栈实现的是一种后进先出(last-in, first-out, LIFO)策略。栈上的INSERT操作称为压入(PUSH), 而无元素参数的DELETE操作称为弹出(POP)。伪码:STACK-EMPTY(S) if S.top == 0 return TURE else return FALSEPUSH(S, x) S.top = S.top + 1 S[S.top] = xPOP(S) if STACK-E...
阅读全文
posted @
2013-04-18 20:27
Anthony Li
阅读(744)
推荐(0) 编辑
【CLRS】《算法导论》读书笔记(三):计数排序(Counting sort)、基数排序(Radix sort)和桶排序(Bucket sort)
摘要:计数排序(Counting sort)维基百科:http://en.wikipedia.org/wiki/Counting_sort时间复杂度:O(n)技术排序的基本思想:对每一个输入元素 x ,确定小于 x 的元素个数。利用这一信息,就可以直接把 x 放到它在输出数组中的位置上了。伪码:COUNTING-SORT(A, B, k) let C[0 .. k] be a new array for i = 0 to k C[i] = 0 for j = 1 to A.length C[A[j]] = C[A[j]] + 1 // C[i] now contains the ...
阅读全文
posted @
2013-03-14 21:25
Anthony Li
阅读(525)
推荐(0) 编辑
【CLRS】《算法导论》读书笔记(二):快速排序(Quicksort)
摘要:快速排序(Quicksort)维基百科:http://en.wikipedia.org/wiki/Quick_sort平均时间复杂度:O(nlogn)示例:[6, 5, 3, 1, 8, 7, 2, 4]快速排序三步分治过程:分解:数组 A[p .. r] 被划分为两个(可能为空)子数组 A[p .. q - 1] 和 A[q + 1 .. r],使得A[p .. q - 1] 中的每一个元素都小于等于 A[q],而 A[q] 也小于等于 A[q + 1 .. r] 中的每个元素。其中,计算下标q也是划分过程的一部分。解决:通过递归调用快速排序,对数组 A[p .. q - 1] 和 A[q
阅读全文
posted @
2013-03-10 21:08
Anthony Li
阅读(707)
推荐(0) 编辑
【CLRS】《算法导论》读书笔记(一):堆排序(Heapsort)
摘要:堆排序(Heapsort)维基百科:http://en.wikipedia.org/wiki/Heapsort时间复杂度:O(nlogn)示例:[6, 5, 3, 1, 8, 7, 2, 4]1、堆(Heap)维基百科:http://en.wikipedia.org/wiki/Heap_(data_structure)Incomputer science, aheapis a specializedtree-baseddata structurethat satisfies theheap property:IfAis a parentnodeofBthen key(A) is ordered
阅读全文
posted @
2013-03-04 15:21
Anthony Li
阅读(727)
推荐(0) 编辑