摘要: 排序算法时间的下界决策树模型:比较排序可以被抽象地视为决策树最坏情况下界:在决策树中, 从根到任意一个可达叶结点之间最长路径的长度,表示对应的排序算法中最坏情况下的比较次数。任意一个比较排序算法在最坏情况下,都需要做Ω(nlgn)次的比较堆排序和合并排序都是渐近最优的比较排序算法 阅读全文
posted @ 2012-05-06 16:25 qiangzhu 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 快速排序对包含n个数的输入数组,最坏情况运行时间为Θ(n2), 但快速排序通常是用于排序的最佳的实用选择,这是因为其平均性能相当好:期望的运行时间为Θ(nlgn), 且Θ(nlgn)记号中隐含的常数因子很小,另外它还能进行就地排序。伪码:QUICKSORT(A, p, r) if p < r then q ← PARTITION(A, p, r) QUICKSORT(A, p, q - 1) QUICKSORT(A, q + 1, r)数组划分:PARTITION(A, p, r) x ← A[r] i ← p - 1 for j ← p to r - 1 ... 阅读全文
posted @ 2012-05-06 16:00 qiangzhu 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 优先级队列是一种用来维护一组元素构成的集合S的数据结构,这一组元素中的每一个都有一个关键字key。一个最大优先级队列支持以下操作:INSERT(S, x): 把元素x插入集合SMAXIMUM(S): 返回S中具有最大关键字的元素EXTRACT-MAX(S): 去掉并返回S中得具有最大关键字的元素INCREASE-KEY(S, x, k): 将元素x的关键字的值增加到k,这里k值不能小于x的原关键字的值HEAP-MAXIMUM(A) return A[1]HEAP-EXTRACT-MAX(A) if heap-size[A] < 1 then error "heap underf 阅读全文
posted @ 2012-05-06 15:24 qiangzhu 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 堆排序的运行时间为Θ(nlgn),它是一种原地排序算法:在任何时候,数组中只有常数个元素存储在输入数组以外;对数据结构是一种数组对象,它可以被视为一棵完全二叉树。树中得每个结点与数组中存放该结点值的那个元素对应。树的每一层都是填满的,最后一层可能除外,表示堆的数组A是一个具有两个属性的对象:length[A]是数组中的元素个数,heap-size[A]是存放A中的堆元素个数。给定某个结点的下标 i , 其父结点PARENT(i),左儿子LEFT(i)和右儿子RIGHT(i)的下标可以计算出来:PARENT(i) return i/2LEFT(i) return 2 * iRIGHT(i) .. 阅读全文
posted @ 2012-05-06 14:27 qiangzhu 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 伪码:BUBBLESORT(A) for i ← 1 to length[A] do for j ← length[A] downto i + 1 do if A[j] < A[j - 1] then exchange A[j] ↔ A[j - 1]Java 实现 public void bubbleSort(int[] a) { int len = a.length; for (int i = 0; i < len; i++) { for (int j = len - 1; j > i... 阅读全文
posted @ 2012-05-06 09:57 qiangzhu 阅读(209) 评论(0) 推荐(0) 编辑
摘要: MERGE(A, p, q, r),其中A是个数组,p, q和r是下标。满足p<=q<r.该过程假设子数组A[p..q]和A[q+1..r]都已排好序;MERGE过程的时间代价为Θ(n), 其中n=r-p+1是待合并的元素个数。伪码:MERGE(A, p, q, r) n1 ← q - p + 1 n2 ← r - q create arrays L[1.. n1+1] and R[1.. n2+1] for i ← 1 to n1 do L[i] ← A[p + i - 1] for j ← 1 to n2 do R[j] ← A[q + j] L[n1 + 1] ←... 阅读全文
posted @ 2012-05-05 22:18 qiangzhu 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 伪码:INSERTION-SORT(A) for j ← 2 to length(A) do key ← A[j] i ← j - 1 while i > 0 and A[i] > key do A[i + 1] ← A[i] i ← i - 1 A[i + 1] ← keyJava 实现: public void insertionSort(int[] a) { int len = a.length; for (int j = 1; j < len; j++) { i... 阅读全文
posted @ 2012-05-05 21:07 qiangzhu 阅读(159) 评论(0) 推荐(0) 编辑
摘要: HTML elements can be displayed either inblockorinlinestyle.The 3 ways that HTML elements can be displayedAll HTML elements are naturally displayed in one of the following ways:BlockTakes up the full width available, with a new line before and after (display:block;)InlineTakes up only as much width a 阅读全文
posted @ 2012-05-05 19:54 qiangzhu 阅读(555) 评论(0) 推荐(0) 编辑
摘要: This is a problem I’ve come across frequently, and since it has come up again recently, I thought I’d explore this issue in the hope that it will save others some trouble. There are so many problems that this one issue can lead to that it’s baffling browsers still behave this way. The issue? An HTML 阅读全文
posted @ 2012-05-05 19:34 qiangzhu 阅读(230) 评论(0) 推荐(0) 编辑
摘要: As many of you must have read or realised(i did) while working with it, MS Internet Explorer doesn't allow you to set the innerHTML property of any table related tag(table, thead, tbody, tr except for td). It says "Unknown Runtime Exception". You are provided with explicit methods to h 阅读全文
posted @ 2012-05-05 19:33 qiangzhu 阅读(211) 评论(0) 推荐(0) 编辑