算法导论(CLRS, 2nd) 个人答案 Ch2 end of chapter
摘要:2-1:2-2:a) loop invariant,initial condition, termination condition.b) A[j] is thesmallest element in A[j .. length[A]]. initialization: at the start of the loop, j = length[A].It's the smallest element in A[length[A] ~ length[A]] (because it'sthe only element). maintenance: if j = k is the s
阅读全文
算法导论(CLRS, 2nd) 个人答案 Ch2.3
摘要:2.3-1:2.3-2:function MERGE-IMPROVED(A,p,q,r){ create array B[0 ... r - p]; int i = p, j = q+1, t =0; while(i<=q && j<=r){ if(A[i] >= A[j]){ B[t++] = A[j++]; } else{ B[t++] = A[i++]; } } if(i>q){ // i pile exhaustedwhile(j<=r) B[t++] = A...
阅读全文