intro to algorithms
文章平均质量分 81
Owner_Of_A_Littledog
这个作者很懒,什么都没留下…
展开
-
算法导论 - 1 - Insertion sort
伪代码1.insertion-sort(A)for j=1 to A.length-1 key=A[j] //insert A[j] into sorted sequence A[0,...,j-2] i=j-1 while(i>=0&&A[i]>key) A[i+1]=A[i] i=i-1 A[i+1]=key...原创 2018-07-02 19:36:04 · 165 阅读 · 0 评论 -
算法导论 - 10 - Dijkstra、Bellman-Ford、Bi-Directional search
伪代码1.initialize(G,s)for v in G v.d=INFs.d=02.relax(u,v,w)if v.d>u.d+w(u,v) v.d=u.d+w(u,v)3.min-heapify(Q,i)m=Q.lengthif 2*i<=m if Q[i].d>Q[2*i].d smallest=2*i else s...原创 2018-07-06 15:46:06 · 307 阅读 · 0 评论 -
算法导论 - 9 - BFS 、DFS、Topological sort
伪代码1.BFS(x)s=new queues.push(x)while !s.empty() u=s.front s.pop u.visit=true for v has edge(u,v) if !v.visit // !!!only put not-visit node into queue s.push(v)2.DFS(G) //...原创 2018-07-06 00:23:55 · 184 阅读 · 0 评论 -
算法导论 - 8 - Direct address、Chain hash、Open addressing hash
伪代码/** * following are for direct-address**/1.direct-address-search(T,k) return T[k]2.direct-address-insert(T,x) T[x.key]=x3.direct-address-delete(T,x) T[x.key]=NULL/** * following are for ha...原创 2018-07-05 20:53:44 · 302 阅读 · 0 评论 -
算法导论 - 7 - Bucket sort
伪代码1.//bucketsize is up to the maximum number in ABucket-sort(A,bucketsize)B[0,...,bucketsize-1]=new node Arrayfor i=0 to bucketsize-1 B[i]=new nodefor i=0 to A.length-1 index=|_A[i]/10_| if ...原创 2018-07-04 22:37:43 · 125 阅读 · 0 评论 -
算法导论 - 6 - Counting sort、Radix sort
伪代码1.Counting sort(A,B,k)//numbers in A vary from 0 to k , A[1,...,n] , B[1,...,n]//B is required for producing a sorted arrayC[0,..,k]=new array for i=0 to k C[i]=0for i=1 to n // n=A.length C[...原创 2018-07-04 21:45:41 · 135 阅读 · 0 评论 -
算法导论 - 5 - Red-Black Tree
性质(5个)每个结点不是红色就是黑色根结点黑色每个叶子结点(NIL)黑色每个红色结点有两个黑色的子结点每个结点到其后代所有叶子结点的 简单路径 上,包含相同数目的黑色结点伪代码1.left-rotate(T,x) //x.right!=NULL//when connecting parent and child, first set parent -> child (parent.l/r=c...原创 2018-07-04 21:03:50 · 137 阅读 · 0 评论 -
算法导论 - 4 - Binary Search Tree
伪代码/** *following are three ways to walk through BST**/1.preorder-tree-walk(x)// remember to check whether x is nullif(x!=NULL) print x.key preorder-tree-walk(x.left) preorder-tree-walk(x.rig...原创 2018-07-03 15:06:59 · 105 阅读 · 0 评论 -
算法导论 - 3 - Heap sort (数组)
伪代码1.max-heapify(A,i)//assume left and right both are max heap//pay attention to field 'i' , remember itl=2*ir=2*i+1if l<=A.heap-size and A[i]<A[l] // l must be within A's scope largest=lel...原创 2018-07-02 22:01:30 · 220 阅读 · 0 评论 -
算法导论 - 2 - Merge sort
伪代码1.merge-sort(A,p,r) if(r-p>1) q=p+(r-p)/2 merge-sort(A,p,q+1) merge-sort(A,q+1,r) merge(A,p,q+1,r)2.merge(A,p,q,r)n1=q-pn2=r-qL[0,...,n1]=new arrayR[0,...,n2]=new ...原创 2018-07-02 20:24:48 · 179 阅读 · 0 评论 -
算法导论 - 11 - Dynamic Programming
伪代码1.//given a rod (length = n) and price i("pi" ,i =1,...,n)//r[i] : the maximum value of a rod (whose length = n) , initialize to be -INFmemoized-cut-rod(p,n,r)for i=1 to n r[i]=-INFreturn memoiz...原创 2018-07-07 21:01:56 · 232 阅读 · 0 评论