算法导论1
- 格式:pdf
- 大小:2.95 MB
- 文档页数:32
算法导论复习资料一、选择题:第一章的概念、术语。
二、考点分析:1、复杂度的渐进表示,复杂度分析。
2、正确性证明。
考点:1)正确性分析(冒泡,归并,选择);2)复杂度分析(渐进表示O,Q,©,替换法证明,先猜想,然后给出递归方程)。
循环不变性的三个性质:1)初始化:它在循环的第一轮迭代开始之前,应该是正确的;2)保持:如果在循环的某一次迭代开始之前它是正确的,那么,在下一次迭代开始之前,它也应该保持正确;3)当循环结束时,不变式给了我们一个有用的性质,它有助于表明算法是正确的。
插入排序算法:INSERTION-SORT(A)1 for j ←2 to length[A]2 do key ←A[j]3 ▹Insert A[j] into the sorted sequence A[1,j - 1].4 i ←j - 15 while i > 0 and A[i] > key6 do A[i + 1] ←A[i]7 i ←i - 18 A[i + 1] ←key插入排序的正确性证明:课本11页。
归并排序算法:课本17页及19页。
归并排序的正确性分析:课本20页。
3、分治法(基本步骤,复杂度分析)。
——许多问题都可以递归求解考点:快速排序,归并排序,渐进排序,例如:12球里面有一个坏球,怎样用最少的次数找出来。
(解:共有24种状态,至少称重3次可以找出不同的球)不是考点:线性时间选择,最接近点对,斯特拉算法求解。
解:基本步骤:一、分解:将原问题分解成一系列的子问题;二、解决:递归地解各子问题。
若子问题足够小,则直接求解;三、合并:将子问题的结果合并成原问题的解。
复杂度分析:分分治算法中的递归式是基于基本模式中的三个步骤的,T(n)为一个规模为n的运行时间,得到递归式T(n)=Q(1) n<=cT(n)=aT(n/b)+D(n)+C(n) n>c附加习题:请给出一个运行时间为Q(nlgn)的算法,使之能在给定的一个由n个整数构成的集合S和另一个整数x时,判断出S中是否存在有两个其和等于x的元素。
算法导论-顺序统计-快速求第i⼩的元素⽬录1、问题的引出-求第i个顺序统计量2、⽅法⼀:以期望线性时间做选择3、⽅法⼆(改进):最坏情况线性时间的选择4、完整测试代码(c++)5、参考资料内容1、问题的引出-求第i个顺序统计量什么是顺序统计量?及中位数概念在⼀个由元素组成的集合⾥,第i个顺序统计量(order statistic)是该集合第i⼩的元素。
例如,最⼩值是第1个顺序统计量(i=1),最⼤值是第n个顺序统计量(i=n)。
⼀个中位数(median)是它所在集合的“中点元素”。
当n为奇数时,中位数是唯⼀的;当n为偶数时,中位数有两个。
问题简单的说就是:求数组中第i⼩的元素。
那么问题来了:如何求⼀个数组⾥第i⼩的元素呢?常规⽅法:可以⾸先进⾏排序,然后取出中位数。
由于排序算法(快排,堆排序,归并排序)效率能做到Θ(nlogn),所以,效率达不到线性;在本⽂中将介绍两种线性的算法,第⼀种期望效率是线性的,第⼆种效率较好,是在最坏情况下能做到线性效率。
见下⾯两个⼩节;2、⽅法⼀:以期望线性时间做选择这是⼀种分治算法:以为模型:随机选取⼀个主元,把数组划分为两部分,A[p...q-1]的元素⽐A[q]⼩,A[q+1...r]的元素⽐A[q]⼤。
与快速排序不同,如果i=q,则A[q]就是要找的第i⼩的元素,返回这个值;如果i < q,则说明第i⼩的元素在A[p...q-1]⾥;如果i > q,则说明第i⼩的元素在A[q+1...r]⾥;然后在上⾯得到的⾼区间或者低区间⾥进⾏递归求取,直到找到第i⼩的元素。
下⾯是在A[p...q]中找到第i⼩元素的伪码:1 RandomSelect(A,p, q,k)//随机选择统计,以期望线性时间做选择2 {3if (p==q) return A[p];4int pivot=Random_Partition(A,p,q);//随机选择主元,把数组进⾏划分为两部分5int i=pivot-p+1;6if (i==k )return A[pivot];7else if (i<k) return RandomSelect(A,pivot+1,q,k-i);//第k⼩的数不在主元左边,则在右边递归选择8else return RandomSelect(A,p,pivot-1,k);//第k⼩的数不在主元右边,则在左边递归选择9 }在最坏情况下,数组被划分为n-1和0两部分,⽽第i个元素总是落在n-1的那部分⾥,运⾏时间为Ө(n^2);但是,除了上述很⼩的概率情况,其他情况都能达到线性;在平均情况下,任何顺序统计量都可以在线性时间Θ(n)内得到。
算法导论:找零钱问题题⽬假设有1元、2元、5元、10元、20元、50元、100元、200元⾯额的硬币或者纸币。
现在需要N元钱,有多少种零钱组合⽅式?解题DFS⽐较简单public void DFS(int m,int[]A,int start,ArrayList<String>result,String str){if(m == 0){result.add(str);return;}if(A[start]> m){return;}for(int i = start;i<A.length;i++){DFS(m - A[i],A,i,result,str+ " "+A[i]);}}如上:1.判断是否是 0是,保存2.是否⾮法3.遍历组合可能验证结果正确当然这样会有许多重合的⼦问题,更改为动态规划,定义数组保存中dp[j] = dp[j] + dp[j -A[i]]; // ⾯值j的零钱可以写出:j = A[i] + (j - A[i]) 求出所有组合⽅式就是答案public void DP(int money,int[]A){int dp[] = new int[money+1]; // dp[j] 表⽰ j元钱的零钱的组合⽅式dp[0] = 1;for(int i = 0;i<A.length;i++){for(int j = A[i];j<= money;j++){dp[j] = dp[j] + dp[j -A[i]]; // ⾯值j的零钱可以写出:j = A[i] + (j - A[i]) 求出所有组合⽅式就是答案}}System.out.println(dp[money]);}然⽽贪⼼的转不过去,⽹上只看到使得找零的硬币数量最少的硬币数量,⽽是找零⽅式的数量public void Greedy(int money,int[] A){int num = 0;for(int i =A.length-1;i>=0;i--){num=num+money/A[i]; //先把⾯值较⼤的找了money = money%A[i];}System.out.println(num);}所有程序package greedy;import java.util.*;public class changeMoney {public void DP(int money,int[]A){int dp[] = new int[money+1]; // dp[j] 表⽰ j元钱的零钱的组合⽅式dp[0] = 1;// 初始是 1 才能dp[j] = dp[j] + ** 才能增加for(int i = 0;i<A.length;i++){for(int j = A[i];j<= money;j++){dp[j] = dp[j] + dp[j -A[i]]; // ⾯值j的零钱可以写出:j = A[i] + (j - A[i]) 求出所有组合⽅式就是答案 }}System.out.println(dp[money]);}public void Greedy(int money,int[] A){int num = 0;for(int i =A.length-1;i>=0;i--){num=num+money/A[i]; //先把⾯值较⼤的找了money = money%A[i];}System.out.println(num);}public void DFS(int m,int[]A,int start,ArrayList<String>result,String str){if(m == 0){result.add(str);return;}if(A[start]> m){return;}for(int i = start;i<A.length;i++){DFS(m - A[i],A,i,result,str+ " "+A[i]);}}public static void main(String[] args){changeMoney cM = new changeMoney();int[] A={1,2,5,10,20,50,100,200};ArrayList<String> result = new ArrayList<String>();int money = 200;//73682cM.DFS(money,A,0,result,"");System.out.println(result.size());cM.DP(money, A);//73682cM.Greedy(money, A);//1}}。
《算法设计与分析》复习提纲2014.7.51 引言(ch1)1.什么是算法及其特征算法(Algorithm)是通过一个有限的指令序列集合对特定问题进行求解的一种计算执行描述。
算法特征:(1)输入:一个算法具有零个或多个取自指定集合的输入值;(2)输出:对每一次输入,算法具有一个或多个与输入值相联系的输出值;(3)确定性:算法的每一个指令步骤都是明确的;(4)有限性:对每一次输入,算法都必须在有限步骤(即有限时间)内结束;(5)正确性:对每一次输入,算法应产生出正确的输出值;(6)通用性:算法的执行过程可用于所有同类求解问题,而不仅适用于特殊输入。
2.问题实例和问题规模问题实例是指需要计算同一个结果的问题的所有输入。
问题规模是指输入实例的大小,而输入实例是指问题的具体计算例子2 算法初步(ch2)1.插入排序算法1)算法步骤:从左到右扫描数据A,扫描到一个元素,将A[j]与其左边的元素从右到左依次比较,若比之小,则将其之前元素后移,插入A【j】,直至A【j】比他前面的元素大,扫描A中的下一个元素2)伪代码:InsertSort(A){for j=2 to A.length //第一层循环{Key=A[j]i=j-1While i>0 and a[i]>key //第二层循环{A[i+1]=A[i]}i=i-1A[i+1]=key}}2.算法复杂性及其度量(1)时间复杂性和空间复杂性;(2)最坏、最好和平均情形复杂性;顺序情况下B(n)=O(n)、倒序情况下W(n)=O(n2)、A(n)=O(n2)<W(n)空间复杂性:需要常数个额外的临时空间存储临时数据2.插入排序的最坏、最好和平均时间最坏O(n2)、最好O(n)和平均时间O(n2),空间复杂度是O(1),稳定排序3.归并排序算法及其时间复杂性-时间Θ(n log n))1)算法步骤分解:分解待排序的n个元素的序列为各具n/2个元素的两个子序列解决:适用归并排序递归的排序2个子序列合并:从左到有遍历2个子序列,比较最前面的元素,将较小的元素移出子序列合并到上级序列的末尾,循环进行上2步,直接所有元素都被合并到上级序列,公进行r-p+1次;2)伪代码:MERGE-SORT(A,p,r){if p<rq=向下取整(p+r)/2MERGE-SORT(A,p,q);MERGE-SORT(A,q+1,r)MERGE(A,p,q,r)}MERGE(A,p,q,r){N1=q-p+1N2=r-q将A拆成长度分别为N1、n2的2个子数组L,RL,R的末尾元素的后一个元素取值无穷大,作为哨兵;i=1,j=1for k=p to rif L[i]<=R[j]A[k]=L[i]i=i+1elseA[k]=R[j]j=j+1}3函数增长率(ch3)1.渐近记号O、Ω、θ的定义及其使用1)O渐进上界:0<=f(n)<=C(g(n))当n->∞, f(n)的阶小与g(n)的阶2)Ω渐进下界:0<=C(g(n)) <=f(n)当n->∞, f(n)的阶大与g(n)的阶3)Θ渐紧界:0<=C1(g(n)) <=f(n) <=C2(g(n))当n->∞, f(n)的阶与g(n)的阶相等2.标准复杂性函数及其大小关系(1)多项式时间阶的大小O(1) < O(log n) < O(n) < O(n*log n) < O(n²) < O(n3)(2)指数时间阶的大小O(2n) <O(n!) < O(n n)3.和式界的证明方法1)数学归纳法猜测解->证明2)对象限界最大最小项限界;几何级数限界;3)和式分解简单的一分为二;更复杂的划分;积分近似;4)Knuth求和:使用数学归纳法;使用摄动法;使用递归;使用积分;使用二重求和;使用有限演算;使用母函数。
Introduction to Algorithms September 24, 2004Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 7Problem Set 1 SolutionsExercise 1-1. Do Exercise 2.3-7 on page 37 in CLRS.Solution:The following algorithm solves the problem:1.Sort the elements in S using mergesort.2.Remove the last element from S. Let y be the value of the removed element.3.If S is nonempty, look for z=x−y in S using binary search.4.If S contains such an element z, then STOP, since we have found y and z such that x=y+z.Otherwise, repeat Step 2.5.If S is empty, then no two elements in S sum to x.Notice that when we consider an element y i of S during i th iteration, we don’t need to look at the elements that have already been considered in previous iterations. Suppose there exists y j∗S, such that x=y i+y j. If j<i, i.e. if y j has been reached prior to y i, then we would have found y i when we were searching for x−y j during j th iteration and the algorithm would have terminated then.Step 1 takes �(n lg n)time. Step 2 takes O(1)time. Step 3 requires at most lg n time. Steps 2–4 are repeated at most n times. Thus, the total running time of this algorithm is �(n lg n). We can do a more precise analysis if we notice that Step 3 actually requires �(lg(n−i))time at i th iteration.However, if we evaluate �n−1lg(n−i), we get lg(n−1)!, which is �(n lg n). So the total runningi=1time is still �(n lg n).Exercise 1-2. Do Exercise 3.1-3 on page 50 in CLRS.Exercise 1-3. Do Exercise 3.2-6 on page 57 in CLRS.Exercise 1-4. Do Problem 3-2 on page 58 of CLRS.Problem 1-1. Properties of Asymptotic NotationProve or disprove each of the following properties related to asymptotic notation. In each of the following assume that f, g, and h are asymptotically nonnegative functions.� (a) f (n ) = O (g (n )) and g (n ) = O (f (n )) implies that f (n ) = �(g (n )).Solution:This Statement is True.Since f (n ) = O (g (n )), then there exists an n 0 and a c such that for all n √ n 0, f (n ) ←Similarly, since g (n )= O (f (n )), there exists an n � 0 and a c such that for allcg (n ). �f (n ). Therefore, for all n √ max(n 0,n Hence, f (n ) = �(g (n )).�()g n ,0← �),0c 1 � g (n ) ← f (n ) ← cg (n ).n √ n c � 0 (b) f (n ) + g (n ) = �(max(f (n ),g (n ))).Solution:This Statement is True.For all n √ 1, f (n ) ← max(f (n ),g (n )) and g (n ) ← max(f (n ),g (n )). Therefore:f (n ) +g (n ) ← max(f (n ),g (n )) + max(f (n ),g (n )) ← 2 max(f (n ),g (n ))and so f (n ) + g (n )= O (max(f (n ),g (n ))). Additionally, for each n , either f (n ) √max(f (n ),g (n )) or else g (n ) √ max(f (n ),g (n )). Therefore, for all n √ 1, f (n ) + g (n ) √ max(f (n ),g (n )) and so f (n ) + g (n ) = �(max(f (n ),g (n ))). Thus, f (n ) + g (n ) = �(max(f (n ),g (n ))).(c) Transitivity: f (n ) = O (g (n )) and g (n ) = O (h (n )) implies that f (n ) = O (h (n )).Solution:This Statement is True.Since f (n )= O (g (n )), then there exists an n 0 and a c such that for all n √ n 0, �)f ()n ,0← �()g n ,0← f (n ) ← cg (n ). Similarly, since g (n ) = O (h (n )), there exists an n �h (n ). Therefore, for all n √ max(n 0,n and a c � such thatfor all n √ n Hence, f (n ) = O (h (n )).cc�h (n ).c (d) f (n ) = O (g (n )) implies that h (f (n )) = O (h (g (n )).Solution:This Statement is False.We disprove this statement by giving a counter-example. Let f (n ) = n and g (n ) = 3n and h (n )=2n . Then h (f (n )) = 2n and h (g (n )) = 8n . Since 2n is not O (8n ), this choice of f , g and h is a counter-example which disproves the theorem.(e) f(n)+o(f(n))=�(f(n)).Solution:This Statement is True.Let h(n)=o(f(n)). We prove that f(n)+o(f(n))=�(f(n)). Since for all n√1, f(n)+h(n)√f(n), then f(n)+h(n)=�(f(n)).Since h(n)=o(f(n)), then there exists an n0such that for all n>n0, h(n)←f(n).Therefore, for all n>n0, f(n)+h(n)←2f(n)and so f(n)+h(n)=O(f(n)).Thus, f(n)+h(n)=�(f(n)).(f) f(n)=o(g(n))and g(n)=o(f(n))implies f(n)=�(g(n)).Solution:This Statement is False.We disprove this statement by giving a counter-example. Consider f(n)=1+cos(�≈n)and g(n)=1−cos(�≈n).For all even values of n, f(n)=2and g(n)=0, and there does not exist a c1for which f(n)←c1g(n). Thus, f(n)is not o(g(n)), because if there does not exist a c1 for which f(n)←c1g(n), then it cannot be the case that for any c1>0and sufficiently large n, f(n)<c1g(n).For all odd values of n, f(n)=0and g(n)=2, and there does not exist a c for which g(n)←cf(n). By the above reasoning, it follows that g(n)is not o(f(n)). Also, there cannot exist c2>0for which c2g(n)←f(n), because we could set c=1/c2if sucha c2existed.We have shown that there do not exist constants c1>0and c2>0such that c2g(n)←f(n)←c1g(n). Thus, f(n)is not �(g(n)).Problem 1-2. Computing Fibonacci NumbersThe Fibonacci numbers are defined on page 56 of CLRS asF0=0,F1=1,F n=F n−1+F n−2for n√2.In Exercise 1-3, of this problem set, you showed that the n th Fibonacci number isF n=�n−� n,�5where �is the golden ratio and �is its conjugate.A fellow 6.046 student comes to you with the following simple recursive algorithm for computing the n th Fibonacci number.F IB(n)1 if n=02 then return 03 elseif n=14 then return 15 return F IB(n−1)+F IB(n−2)This algorithm is correct, since it directly implements the definition of the Fibonacci numbers. Let’s analyze its running time. Let T(n)be the worst-case running time of F IB(n).1(a) Give a recurrence for T(n), and use the substitution method to show that T(n)=O(F n).Solution: The recurrence is: T(n)=T(n−1)+T(n−2)+1.We use the substitution method, inducting on n. Our Induction Hypothesis is: T(n)←cF n−b.To prove the inductive step:T(n)←cF n−1+cF n−2−b−b+1← cF n−2b+1Therefore, T(n)←cF n−b+1provided that b√1. We choose b=2and c=10.∗{For the base case consider n0,1}and note the running time is no more than10−2=8.(b) Similarly, show that T(n)=�(F n), and hence, that T(n)=�(F n).Solution: Again the recurrence is: T(n)=T(n−1)+T(n−2)+1.We use the substitution method, inducting on n. Our Induction Hypothesis is: T(n)√F n.To prove the inductive step:T(n)√F n−1+F n−2+1√F n+1Therefore, T(n)←F n. For the base case consider n∗{0,1}and note the runningtime is no less than 1.1In this problem, please assume that all operations take unit time. In reality, the time it takes to add two numbers depends on the number of bits in the numbers being added (more precisely, on the number of memory words). However, for the purpose of this problem, the approximation of unit time addition will suffice.Professor Grigori Potemkin has recently published an improved algorithm for computing the n th Fibonacci number which uses a cleverly constructed loop to get rid of one of the recursive calls. Professor Potemkin has staked his reputation on this new algorithm, and his tenure committee has asked you to review his algorithm.F IB�(n)1 if n=02 then return 03 elseif n=14 then return 15 6 7 8 sum �1for k�1to n−2do sum �sum +F IB�(k) return sumSince it is not at all clear that this algorithm actually computes the n th Fibonacci number, let’s prove that the algorithm is correct. We’ll prove this by induction over n, using a loop invariant in the inductive step of the proof.(c) State the induction hypothesis and the base case of your correctness proof.Solution: To prove the algorithm is correct, we are inducting on n. Our inductionhypothesis is that for all n<m, Fib�(n)returns F n, the n th Fibonacci number.Our base case is m=2. We observe that the first four lines of Potemkin guaranteethat Fib�(n)returns the correct value when n<2.(d) State a loop invariant for the loop in lines 6-7. Prove, using induction over k, that your“invariant” is indeed invariant.Solution: Our loop invariant is that after the k=i iteration of the loop,sum=F i+2.We prove this induction using induction over k. We assume that after the k=(i−1)iteration of the loop, sum=F i+1. Our base case is i=1. We observe that after thefirst pass through the loop, sum=2which is the 3rd Fibonacci number.To complete the induction step we observe that if sum=F i+1after the k=(i−1)andif the call to F ib�(i)on Line 7 correctly returns F i(by the induction hypothesis of ourcorrectness proof in the previous part of the problem) then after the k=i iteration ofthe loop sum=F i+2. This follows immediately form the fact that F i+F i+1=F i+2.(e) Use your loop invariant to complete the inductive step of your correctness proof.Solution: To complete the inductive step of our correctness proof, we must show thatif F ib�(n)returns F n for all n<m then F ib�(m)returns m. From the previous partwe know that if F ib�(n)returns F n for all n<m, then at the end of the k=i iterationof the loop sum=F i+2. We can thus conclude that after the k=m−2iteration ofthe loop, sum=F m which completes our correctness proof.(f) What is the asymptotic running time, T�(n), of F IB�(n)? Would you recommendtenure for Professor Potemkin?Solution: We will argue that T�(n)=�(F n)and thus that Potemkin’s algorithm,F ib�does not improve upon the assymptotic performance of the simple recurrsivealgorithm, F ib. Therefore we would not recommend tenure for Professor Potemkin.One way to see that T�(n)=�(F n)is to observe that the only constant in the programis the 1 (in lines 5 and 4). That is, in order for the program to return F n lines 5 and 4must be executed a total of F n times.Another way to see that T�(n)=�(F n)is to use the substitution method with thehypothesis T�(n)√F n and the recurrence T�(n)=cn+�n−2T�(k).k=1Problem 1-3. Polynomial multiplicationOne can represent a polynomial, in a symbolic variable x, with degree-bound n as an array P[0..n] of coefficients. Consider two linear polynomials, A(x)=a1x+a0and B(x)=b1x+b0, where a1, a0, b1, and b0are numerical coefficients, which can be represented by the arrays [a0,a1]and [b0,b1], respectively. We can multiply A and B using the four coefficient multiplicationsm1=a1·b1,m2=a1·b0,m3=a0·b1,m4=a0·b0,as well as one numerical addition, to form the polynomialC(x)=m1x2+(m2+m3)x+m4,which can be represented by the array[c0,c1,c2]=[m4,m3+m2,m1].(a) Give a divide-and-conquer algorithm for multiplying two polynomials of degree-bound n,represented as coefficient arrays, based on this formula.Solution:We can use this idea to recursively multiply polynomials of degree n−1, where n isa power of 2, as follows:Let p(x)and q(x)be polynomials of degree n−1, and divide each into the upper n/2 and lower n/2terms:p(x)=a(x)x n/2+b(x),q(x)=c(x)x n/2+d(x),where a(x), b(x), c(x), and d(x)are polynomials of degree n/2−1. The polynomial product is thenp(x)q(x)=(a(x)x n/2+b(x))(c(x)x n/2+d(x))=a(x)c(x)x n+(a(x)d(x)+b(x)c(x))x n/2+b(x)d(x).The four polynomial products a(x)c(x), a(x)d(x), b(x)c(x), and b(x)d(x)are computed recursively.(b) Give and solve a recurrence for the worst-case running time of your algorithm.Solution:Since we can perform the dividing and combining of polynomials in time �(n), recursive polynomial multiplication gives us a running time ofT(n)=4T(n/2)+�(n)=�(n2).(c) Show how to multiply two linear polynomials A(x)=a1x+a0and B(x)=b1x+b0using only three coefficient multiplications.Solution:We can use the following 3 multiplications:m1=(a+b)(c+d)=ac+ad+bc+bd,m2=ac,m3=bd,so the polynomial product is(ax+b)(cx+d)=m2x2+(m1−m2−m3)x+m3.� (d) Give a divide-and-conquer algorithm for multiplying two polynomials of degree-bound nbased on your formula from part (c).Solution:The algorithm is the same as in part (a), except for the fact that we need only compute three products of polynomials of degree n/2 to get the polynomial product.(e) Give and solve a recurrence for the worst-case running time of your algorithm.Solution:Similar to part (b):T (n )=3T (n/2) + �(n )lg 3)= �(n �(n 1.585)Alternative solution Instead of breaking a polynomial p (x ) into two smaller polynomials a (x ) and b (x ) such that p (x )= a (x ) + x n/2b (x ), as we did above, we could do the following:Collect all the even powers of p (x ) and substitute y = x 2 to create the polynomial a (y ). Then collect all the odd powers of p (x ), factor out x and substitute y = x 2 to create the second polynomial b (y ). Then we can see thatp (x ) = a (y ) + x b (y )· Both a (y ) and b (y ) are polynomials of (roughly) half the original size and degree, and we can proceed with our multiplications in a way analogous to what was done above.Notice that, at each level k , we need to compute y k = y 2 (where y 0 = x ), whichk −1 takes time �(1) per level and does not affect the asymptotic running time.。
麻省理工学院-算法导论关于课本的介绍如下:本书自第一版出版以来,已经成为世界范围内广泛使用的大学教材和专业人员的标准参考手册。
本书全面论述了算法的内容,从一定深度上涵盖了算法的诸多方面,同时其讲授和分析方法又兼顾了各个层次读者的接受能力。
各章内容自成体系,可作为独立单元学习。
所有算法都用英文和伪码描述,使具备初步编程经验的人也可读懂。
全书讲解通俗易懂,且不失深度和数学上的严谨性。
第二版增加了新的章节,如算法作用、概率分析与随机算法、线性编程等,几乎对第一版的各个部分都作了大量修订。
学过计算机的都知道,这本书是全世界最权威的算法课程的大学课本了,基本上全世界的名牌大学用的教材都是它。
这本书一共四位作者,Thomas H. Cormen,Charles E. Leiserson和Ronald L. Rivest是来自MIT的教授,Clifford Stein是MIT出来的博士,现在哥伦比亚大学做教授,四人姓氏的首字母联在一起即是此书的英文简称(CLRS 2e),其中的第三作者Ronald L. Rivest是RSA算法的老大(算法名字里面的R即是指他),四个超级大牛出的一本书,此书不看人生不能算完整。
再介绍一下课堂录像里面授课的两位MIT的老师,第一位,外表“绝顶聪明”的,是本书的第二作者Charles E. Leiserson,以逻辑严密,风趣幽默享誉MIT。
第二位,留着金黄色的络腮胡子和马尾发的酷哥是Erik Demaine,21岁即取得MIT教授资格的天才,1981出生,今年才25岁,业余爱好是俄罗斯方块、演戏、琉璃、折纸、杂耍、魔术和结绳游戏。
另外,附上该书的中文电子版,pdg转pdf格式,中文版翻译自该书的第一版,中文书名没有使用《算法导论》,而使用的是《现代计算机常用数据结构和算法》,1994年出版时没有得到国外的授权,属于“私自翻译出版”,译者是南京大学计算机系的潘金贵。
课程重点算法导论是麻省理工学院电机工程与计算机科学系“理论计算机科学”集中选修课程的先导科目。
851算法与程序设计参考书目1、数学算法参考书目1.《算法导论(原书第3版)》该书是算法领域的经典教材,由Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, 和Clifford Stein合著。
本书系统地介绍了算法设计与分析的基本思想、技巧和常用的高效算法,包含了大量的算法示例和习题。
2.《算法(第4版)》该书由Robert Sedgewick和Kevin Wayne合著,结合了理论和实践,对算法进行了详尽的介绍,并应用了Java编程语言实现了算法的示例。
本书涵盖了排序算法、图算法、字符串算法、查找算法等不同领域的算法。
3.《数据结构与算法分析:Java语言描述(原书第3版)》该书由Mark Allen Weiss撰写,详细介绍了算法和数据结构的基本概念,并通过Java语言给出了算法的实现。
本书将数据结构和算法设计结合起来,并通过具体的实例和应用来帮助读者理解和掌握。
4.《编程珠玑》该书由Jon Bentley撰写,通过一系列有趣的问题和实例,讲解了高效算法设计的思维方式和技巧。
本书强调的是实际问题的解决方法,旨在培养读者对算法和程序设计的直观理解和创造力。
5.《数据结构与算法分析,C语言描述(原书第2版)》该书由Mark Allen Weiss撰写,通过C语言描述了常见的数据类型和算法的实现方式,包括线性表、树、图、排序算法等。
本书注重实践和实现细节,并提供了大量的习题和实验,帮助读者加深对算法和数据结构的理解。
6.《编程之美:微软技术面试心得》该书由Gavin Bierman, Noah Snyder和Jerry Su合著,介绍了微软技术面试中常见的问题和算法题,并给出了解决思路和策略。
本书通过解读面试问题的背后原理,帮助读者提升解决实际问题的能力和面试技巧。
7.《算法设计与分析实例讲义》该书由张铱珩等人编写,详细介绍了常见的算法和技术,并给出了实现的示例和分析。
第1章算法在计算中的作用章算法在计算中的作用什么是算法?为什么要对算法进行研究?相对于计算机中使用的其他技术来说,算法的作用是什么?在本章中,我们就要来回答这些问题. 1. 1算法算法简单来说,所谓抹法(also*llem)就是定义良好的计算过程,它取一个或一组值作为输入,并产生出一个或一组值作为输出。
并产生出一个或一组值作为输出。
亦即,亦即,算法就是一系列的计算步驭,算法就是一系列的计算步驭,用来将输人数据转换用来将输人数据转换成输出结果。
成输出结果。
我们还可以将算法看作是一种工具。
用来解决一个具有良好规格说明的计算问题。
有关该问题的表述可以用通用的语言,来规定所需的输人/输出关系。
与之对应的算法则描迷了一个特定的计算过程,用于实现这一输人/输出关系输出关系例如.假设需要将一列数按非降顺序进行排序。
在实践中,这一问皿经常山现。
它为我们引入许多标准的算法设计技术和分析工具提供了丰富的问题场景。
下面是有关该排序间题的形式化定义,的形式化定义,输入:由n 个数构成的一个序列编出:对输人序列的一个排列(重排) 例如,给定一个输人序列(31. 41. 59. 26, 41, 58).一个排序算法返回的怕出序列是(26, 31. 41. 41. 58, 59).这样的一个输人序列称为该排序问趣的一个实例G .-e)。
一般来说,。
一般来说,某一个问题的实例包含了求解该间题所需的输人(它满足有关该同题的表述中所给出的任何限制)。
在计算机科学中,排序是一种基本的操作(很多程序都将它用作一种申间步骤)。
因此,迄今为止,科研人员提出了多种非常好的排序算法。
科研人员提出了多种非常好的排序算法。
对于一项特定的应用来说,对于一项特定的应用来说,对于一项特定的应用来说,如何选择最如何选择最佳的排序算法要考虑多方面的因素,其中最主要的是考虑待排序的数据项数、这些数据项已排好序的程度、对数据项取值的可能限制、对数据项取值的可能限制、打算采用的存储设备的类型打算采用的存储设备的类型〔内存、磁盘、磁带)等。