05 2012 档案

摘要:红黑树是一种二叉查找树,树中每个加点包含五个域:color,key,left, right和p。红黑树性质:1)每个结点或是红的,或是黑的2)根结点是黑的3)每个叶结点是黑的4)如果一个结点是红的,则它的两个儿子都是黑的5)对每个结点,从该结点到其子孙结点的所有路径上包含相同数目的黑结点 阅读全文
posted @ 2012-05-29 14:30 qiangzhu 阅读(212) 评论(0) 推荐(0)
摘要:中序遍历INORDER-TREE-WALK(x)if x != NIL INORDER-TREE-WALK(x.left) print x.key INORDER-TREE-WALK(x.right)查找TREE-SEARCH(x,k)if x == NIL or k == x.key return xif k < x.key return TREE-SEARCH(x.left, k)else return TREE-SEARCH(x.right, k)最大关键字TREE-MAXIMUM(x)while(x.right != NIL) ... 阅读全文
posted @ 2012-05-28 20:32 qiangzhu 阅读(225) 评论(0) 推荐(0)
摘要:排序算法时间的下界决策树模型:比较排序可以被抽象地视为决策树最坏情况下界:在决策树中, 从根到任意一个可达叶结点之间最长路径的长度,表示对应的排序算法中最坏情况下的比较次数。任意一个比较排序算法在最坏情况下,都需要做Ω(nlgn)次的比较堆排序和合并排序都是渐近最优的比较排序算法 阅读全文
posted @ 2012-05-06 16:25 qiangzhu 阅读(158) 评论(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 阅读(184) 评论(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 阅读(303) 评论(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 阅读(330) 评论(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 阅读(219) 评论(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 阅读(209) 评论(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 阅读(169) 评论(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 阅读(572) 评论(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 阅读(239) 评论(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 阅读(224) 评论(0) 推荐(0)
摘要:1.CSS Block vs Inline CSS Display Styleshttp://www.webdesignfromscratch.com/html-css/css-block-and-inline/2.Containing Floatshttp://www.complexspiral.com/publications/containing-floats/http://css-tricks.com/all-about-floats/3.CSS Positioninghttp://www.vanseodesign.com/css/css-positioning/4.CSS Organ 阅读全文
posted @ 2012-05-05 19:32 qiangzhu 阅读(234) 评论(0) 推荐(0)
摘要:Sometimes you want to make a good impression with everyone and seem like you're interested in the rest of the group. Especially when you've just met some new people, it's usually better to lean towards the outgoing end of the scale. Getting that "quiet" label often works agains 阅读全文
posted @ 2012-05-05 19:29 qiangzhu 阅读(546) 评论(0) 推荐(0)
摘要:1.Refactoringhttp://sourcemaking.com/refactoring2.Inversion of Control Containers and the Dependency Injection patternhttp://martinfowler.com/articles/injection.html3.ConCurrentHashMaphttp://www.ibm.com/developerworks/java/library/j-jtp08223/4..Continuous Integrationhttp://martinfowler.com/articles/ 阅读全文
posted @ 2012-05-05 19:28 qiangzhu 阅读(153) 评论(0) 推荐(0)
摘要:The Factory Method Pattern defines an interface for creating an object, but lets subclassed decide which classto instantiate. Factory Method lets a class defer instantiation to subclasses.Dependency Inversion PrincipleDepend upon abstractions. Do not depenfd upon concrete classesGuidelies to follow 阅读全文
posted @ 2012-05-05 17:47 qiangzhu 阅读(524) 评论(0) 推荐(0)
摘要:The State Pattern allows an object to alter its behavior when its internal state changes. Theobject will appear to change its class.State Pattern Diagram:State Pattern VS. Strategy Patternwith the state pattern, we have a set of behavior encapsulated in state objects; at any time thecontextis delega 阅读全文
posted @ 2012-05-04 11:25 qiangzhu 阅读(703) 评论(0) 推荐(0)
摘要:The Composite Pattern allows you to compose objects into tree structures to represent part-wholehierarchies.Composite lets clients treat individual objects and compositions of objects uniformly.The Composite Pattern allows us to build structures of objects in the form of trees that contain bothcompo 阅读全文
posted @ 2012-05-03 20:48 qiangzhu 阅读(477) 评论(0) 推荐(0)