算法分析与设计试卷

合集下载

一份《算法设计与分析》试卷+答案

一份《算法设计与分析》试卷+答案

2006-2007学年度第一学期计算机科学系《算法设计与分析》期末试卷(A)一对于下列各组函数,确定f(n)=O(g(n))是否成立。

(每题5分,共20分)1f(n)=3n,g(n)=nf(n)=O(g(n))成立,因为存在正的常数C和自然数n,使得N>=n时,有F(n)<=Cg(n)2f(n)=nlogn+n,g(n)=logn不成立!N>=n时,有f(n)>=og(n);属于f(n)=πg(n)这种情况3f(n)=log2n,g(n)=logn不成立!当logN>=1时,总有f(n)>=log n,属于f(n)=πg(n)这种情况!4f(n)=5,g(n)=log5成立!总存在一个正的常数C,使得f(n)<=Cg(n)1二分搜索法 int bin_seach ( int k[ ] , int n , int key ) { int low = 0 , high = n=1 , mid ; while ( low <= high ) { mid = ( low + high ) / 2 ; if ( key == k[ mid ] ) return mid ; if ( key > k[ mid ] ) low = mid + 1 ; else high = mid - 1 ; } return -1 ;} T(n)=n 2利用一维一级指针数组及二级指针输出二维数组元素。

#include "stdio.h" void main() { int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; int *arr[3]={a[0],a[1],a[2]}; int i,j,**p; p=arr; for(i=0;i<3;i++){for(j=0;j<4;j++)printf("%3d",a[i][j]));printf("%3d",*(&p[0][0]+i*4+j));printf("%3d",*(p[i]+j));printf("%3d",(*(p+i))[j]);printf("%3d",*(*(p+i)+j));printf("\n");}printf("\n");三 写出下列算法的时间复杂度函数.(每题5分,共10分)————————————装————————————————订}T(n)=12四根据给定的算法求出下列问题的解。

算法设计与分析试卷及答案

算法设计与分析试卷及答案

算法设计与分析1、(1) 证明:O(f)+O(g)=O(f+g)(7分)(2) 求下列函数的渐近表达式:(6分)① 3n 2+10n;② 21+1/n;2、对于下列各组函数f(n)和g(n),确定f(n)=O(g(n))或f(n)=Ω(g(n))或f(n)=θ(g(n)),并简述理由。

(15分)(1);5log )(;log )(2+==n n g n n f (2);)(;log )(2n n g n n f == (3);log )(;)(2n n g n n f == 3、试用分治法对数组A[n]实现快速排序。

(13分)4、试用动态规划算法实现最长公共子序列问题。

(15分)5、试用贪心算法求解汽车加油问题:已知一辆汽车加满油后可行驶n 公里,而旅途中有若干个加油站。

试设计一个有效算法,指出应在哪些加油站停靠加油,使加油次数最少。

(12分)6、试用动态规划算法实现下列问题:设A 和B 是两个字符串。

我们要用最少的字符操作,将字符串A 转换为字符串B ,这里所说的字符操作包括:(1)删除一个字符。

(2)插入一个字符。

(3)将一个字符改为另一个字符。

将字符串A 变换为字符串B 所用的最少字符操作数称为字符串A 到B 的编辑距离,记为d(A,B)。

试设计一个有效算法,对任给的两个字符串A 和B ,计算出它们的编辑距离d(A,B)。

(16分)⎣⎦2/)(;3)(i i g i i f ==。

对于给定的两个整数n 和m ,要求用最少的变换f 和g 变换次数将n 变为m 。

(16分)1、⑴证明:令F(n)=O(f),则存在自然数n 1、c 1,使得对任意的自然数n ≥n 1,有:F(n)≤c 1f(n)……………………………..(2分)同理可令G(n)=O(g),则存在自然数n 2、c 2,使得对任意的自然数n ≥n 2,有:G(n)≤c 2g(n)……………………………..(3分)令c 3=max{c 1,c 2},n 3=max{n 1,n 2},则对所有的n ≥n 3,有: F(n)≤c 1f(n)≤c 3f(n)G(n)≤c 2g(n)≤c 3g(n)……………………………..(5分) 故有:O(f)+O(g)=F(n)+G(n)≤c 3f(n)+c 3g(n)=c 3(f(n)+g(n)) 因此有:O(f)+O(g)=O(f+g)……………………………..(7分) ⑵ 解:① 因为;01033)103(lim 222=+-+∞→n n n n n n 由渐近表达式的定义易知: 3n 2是3n 2+10n 的渐近表达式。

(完整版)算法设计与分析考试题及答案,推荐文档

(完整版)算法设计与分析考试题及答案,推荐文档
法好坏的标准是______________________。 3.某一问题可用动态规划算法求解的显著特征是
____________________________________。 4.若序列 X={B,C,A,D,B,C,D},Y={A,C,B,A,B,D,C,D},请给出序列
X 和 Y 的一个最长公共子序列_____________________________。 5.用回溯法解问题时,应明确定义问题的解空间,问题的解空间至

之分。
5、 f(n)= 6×2n+n2,f(n)的渐进性态 f(n)= O(
)
6、 贪心算法总是做出在当前看来
的选择。也就是说贪心算法并不从整体最优考
虑,它所做出的选择只是在某种意义上的

7、 许多可以用贪心算法求解的问题一般具有 2 个重要的性质:
性质和
性质。
二、简答题(本题 25 分,每小题 5 分)
五、算法理解题(本题 5 分) 设有 n=2k 个运动员要进行循环赛,
现设计一个满足以下要求的比赛日程表:
①每个选手必须与其他 n-1 名选手比赛各一次; ②每个选手一天至多只能赛一次;
③循环赛要在最短时间内完成。
我去(人1)如也果 就n=2k有,循人环赛!最少为需要U进R行扼几天腕; 入站内信不存在向你偶同意调剖沙 (2)当 n=23=8 时,请画出循环赛日程表。
六、算法设计题(本题 15 分) 分别用贪心算法、动态规划法、回溯法设计 0-1 背包问题。要求:说明所使用的算法
策略;写出算法实现的主要步骤;分析算法的时间。 七、算法设计题(本题 10 分)
建议收藏下载本文,以便随时学习! 通过键盘输入一个高精度的正整数 n(n 的有效位数≤240),去掉其中任意 s 个数字后, 剩下的数字按原左右次序将组成一个新的正整数。编程对给定的 n 和 s,寻找一种方案, 使得剩下的数字组成的新数最小。 【样例输入】 178543 S=4 【样例输出】 13

最新算法设计与分析试卷(A)及答案

最新算法设计与分析试卷(A)及答案

考试课程:班级:姓名:学号:-------------------------------------------------密----------------------------------封-----------------------------线---------------------------------------------------------考试课程:班级:姓名:学号:------------------------------------------------- 密 ---------------------------------- 封 ----------------------------- 线 ---------------------------------------------------------参考答案一、填空1、空间复杂度 时间复杂度2、回溯法3、递归算法4、渐进确界或紧致界5、原问题的较小模式 递归技术6、问题的计算复杂性分析有一个共同的客观尺度7、②③④①8、问题的最优解包含其子问题的最优解9、局部最优 10、正确的三、简答题1、高级语言更接近算法语言,易学、易掌握,一般工程技术人员只需要几周时间的培训就可以胜任程序员的工作;高级语言为程序员提供了结构化程序设计的环境和工具,使得设计出来的程序可读性好,可维护性强,可靠性高;高级语言不依赖于机器语言,与具体的计算机硬件关系不大,因而所写出来的程序可植性好、重用率高;把繁杂琐碎的事务交给编译程序,所以自动化程度高,开发周期短,程序员可以集中时间和精力从事更重要的创造性劳动,提高程序质量。

2、 ①不能保证最后求得的解是最佳的;即多半是近似解。

(少数问题除外)②策略容易发现(关键:提取清楚问题中的维度), 而且运用简单,被广泛运用。

③策略多样,结果也多样。

④算法实现过程中,通常用到辅助算法:排序3、解:① 因为:;01-10n n )1-10n n (lim 222=+-+→∞n n 由渐近表达式的定义易知: 1-10n n 22+是n ;的渐近表达式。

算法分析与设计考试样卷.docx

算法分析与设计考试样卷.docx

算法分析与设计复习题1・ Based on what we have discussed in class, state the best asymptotic running time for each of the problems below, using the ^big OtT notation. It is assumed that T(l) =d for some constant din all the recurrences. If you think the problem is NP-complete, state so (no running time should be given in this case). Just state the answers- you do not need to justify them.(1)Deteriniiiiiig the 4r-tli largest element in au unsorted set of size n.(2)In a directed, weighted graph G = (U;E) with positive weights and \V\ = n and\E\ = m, determine the shortest path between a given pair of vertices.(3)T(n) = 40(萝)+ cn2(4)Given a boolean formula in conjunctive normal form (i.e., Ci A C2 A ... A where every Cjcontains an arbitrary number of literals V-ed together),determine whether there exists a truth assignment to the variables satisfying the formula・(5)Given a boolean formula in disjunctive normal form (i.e., Ci V C2 V ... V where every Cicontains an arbitral number of literals together), determine whether there exists a truthassignment, to the variables satisfying the formula.(6)In an n-node rooted tree T、determine the number of leaves whose parent has more thanone chil(1.2.Describe the main ideas of the following strategies, and briefly describe the differences between them.(1)divide-and-conquer;(2)dynamic programming;(3)branch and bound3.During the course we have studied some important classes of algorithms. Three of these are Divide and Conquer Algorithms, Greedy Algorithms and Dynamic Programming Algorithms. Give non-trivial examples of each of these three types of algorithms and describe them in detai. For each example, explain what makes it such an algorithm. (That is, for your example of a greedy algorithm you should explain exactly what makes it a greedy algorithm, and so on.)Solution: There are lot of possible solutions. Natural examples would be: Divide and Conquer: Mergesort Greedy: KruskaPs algorithm. Dynamic Programming:Dijkstra's algorithm or Bellman-Ford^s algorithm.4.(30 points) Choose T or F for each of the following statements.1)The best case running time for quicksort to sort an element array is O(nlogn).2)By the master theorem, the solution to the recurrence T(n)=3T(n/3)+3n isT(n)=O(nlogn).3)Every binary search tree on n nodes has height O(logn).4)By using path compression (Union- Find) technique to analyze Kruskal algorithm,the algorithm^ running time is O(mlog*n+nlog*n).5)Depth-first search of a graph is asymptotically foster than breadth-first search・6)KruskaPs algorithm for finding a minimum spanning tree employs dynamicprogramming ・7)The backtrack technique uses the idea of breath first search to get the optimal value.8)n!=O(2n).9)In the worst ease, merge sort runs in O(n ) time.10)In computer science, all the problems are either in P or NP.11)Kruskal's algorithm is faster Prim's algorithm.12)Divide-and-Conquer is a bottom-up algorithm and Dynamic Programming is a top-down algorithm・13)For an unweighted graph G, Depth-first search algorithm can be used to find theshortest paths f?om a given vertex to other vertices・14)For two decision problems QI and Q2, if QI is polynomial time reducible to Q2, thenQ1 and Q2 have the same difficulty.15)The problems solvable by Dynamic Programming can also be solved by Divide-and-Conquer algorithm.16)A 0(n2)algorithm always takes longer to run than a 0 (logn)algorithm.16)BFS is a linear time algorithm.17)Given n numbers al,...卫n, the median of the smallest ten numbers and the largest tennumbers among them can be computed inO(n) time. T18)Every undirected connected graph on n vertices has exactly n-1 edges. F19)Given n numbers al, an, where for every 1 Wi Wn, ai W {~5, 9, 100}; theirsortedborder can be output in O(n) time. TRUE20)If a problem is NP-complete, it must also be in NP. T21)f a problem is not in P, it must be NP-complete. F22)Given an undirected unweighted graph G in n vertices and m edges and two distinctvertices SH t, the shortest s-t path can be computed in 0(m+n) time. TRUE23)If an algorithm runs in timeO(2 ogn)it actually runs in polynomial time. T24)If we have a 3-SAT formula with 5 clauses, we can decide in polynomial time if it issatisfiable. T25)Every directed acyclic graph has exactly one topological ordering.26)Given a graphG= (V;E)with positive edge weights, the Bellman-Ford algo-rithm andDijkstraM algorithm can produce different shortest-path trees despite alwaysproducing the same shortest-path weights.Solution: True・ Both algorithms are guaranteed to produce the same shortest-path weight, but if there arc multiple shortest paths, Dijkstra^s will choose the shortest path according to the greedy strategy, and Bellman-Ford will choose the shortest pathdepending on the order of relaxations, and the two shortest path trees may be different.27)For all positivef(n), g(n)andh(n), if f(n) =O(g(n))andf(n) = Q(h(n)),then g(n) +h(n)=O (f(n)).Solution: True. This follows fromf(n) =O(g(n)))g(n) =Q(f(n)).5.Algorithm Design(1)Given a graph G=(Y E), use Dcpth-First-Scarch to count the number of connectedcomponents in G.(2) A maximum spanning tree in a weighted graph G is a spanning tree in G with thelargest weight over all spanning trees. Give an efficient algorithm that constructs a maximum spanning tree for a weighted graph G=(V> E), and analyze the running time of your algorithm.(3)Based on Quick Sorting , please write an algorithm to find the k-th smallest element in a list.6.Find the minimal number of multiplications needed to compute the product of four matrices Alx A2 x A3 x A4. Matrix Al has the size 3x2, matrix A2 has the size 2x5,matrix A3 has the sisze 5x4, matrix A4 has the size 4x3・7.The Master Theorem applies to recurrences of the following form:T (n) = aT (n/b) + f{n)where a > 1 and b > 1 are constants and f(n) is an asymptotically positive fiinction.There are 3 cases:1). If there is a constant £ > 0, such that /OO = O(n^b(1~f ), then = 0(/7log/ .2). If there is a constant k > 0, such that f\n) = 0(w logftU log A n) with k > 0, thenT(n) = 0(w,o& a log A+,n).3). If there are small constants e > 0 and 8 <1 such that /(〃)= Q(d呜")andaf(n/h) < for n >d, then T(n) = ©(/(//)).(a)T(n)= 4T(n/2)+n2n'°^a = n^4 = n2 ,/(/?) = ^. Let)1 = 0, then f(n) is 0(/r log* /?). Case 2 applies.Thus, T(n) is 0(/?2 logn)(b)T(n)= 4T(n/2)+nw,og*fl = w log24 = n2 , f(n) = n. Let 8=0.5, is then f(h)O(n2 e). Case 1 applies.Thus, T(n) is 0(/?2)(c)T(n)= 4T(n/2)+n‘n^a = n10824 = n2 , f(n) = n3 .Let 8=0.5, then f(n) is Q(/72+fc).aJ\n/b) = 4f(n/2) = 4((H/2)3) = w3/2Let, then 5 = 1/2 aj\n/b) = ir /2< 8f(n) for all n>l. Case 3 applies.Thus, T(n) is 0(n3)a.T(71) = 2T(n/ 2)4- log nn logh<l = n logz2 = n , f(n)=logn. Let £=0.5 , f(n) is O(n0,5), that is, f(n)isO(n log*a 6)Thus, we are in case 1. This means T(/?) is &(n) by the master method.b.T(H)=8T(H/2)4-H2“log, _ d吧8 = ”3 ,迪尸/ Let £ = 1, n2 is 0(/?3 6), that is, f(n)is O(d°g" a~e).Thus, we are in case 1. This means T(n) is 0(/7 )by the master method.c.T(n) = 16T(n / 2) + (n log n)4n°Sba= H I O S216 = 724 . F(n)= (nlogn)4. Let k = 4 , (n log A?)4 is 0(/74 log* n) , that is, f(n) = 0(d°8"" log火n) . Thus we are in case 2.This means T(n) is 0(n4 log5n)d.T(n) = 7T(n/3) + nThis means T(/?) is ®(n log37)e.T(n) = 9T(n / 3) + n3 log nn OSb° = n°S39 = n2, f(n)=n s logn. let 6: = 1 , then, n3 logn is 0(〃"'),that is f{n) isaf(n /h) = 9f (n / 3) = 9((n / 3)3 log(n /3)) = (n3 / 3) log(/? / 3)let 3 = 1/3, d=l, then, of (nib) = (n3 / 3) log(n / 3) < (n3 / 3) log(w) — Sf (n) for all n>=d. Thus, we are in case 3.This means T(n) is &(n3 log/?)8.You have an algorithm that takes as input integers al;•…am The running time of your algorithm isO(al+a2+...+an)> Is this a polynomial time algorithm? Explain your answer NO EXPONTENTIAL ALGORITHM9.You are given an undirected graph G= (V,E).a.Show how to modify the BFS algorithm so that it decides whether G contains a cycle.b.What is the running time of your algorithm?Solutiona.We run BFS, and whenever we encounter an already seen vertexv from a node u, we stop and state that there exists a cycle in the graph (in fact, the edge (u,v) closes this cycle). If wc do not encounter an already seen vertex,wc terminate the execution of BFS and report thatGdoes not contain a cycle.b.The running time isO(n). Indeed, if the graph does not contain a cycle then it is a tree, and then|E| =|V| 一1,which implies that the running time of BFS in this case isO(|V| +|E|) = O(|V|). If there is a cycle in G, then wetraverse onlyO(|V|) edges ofG. In this case each vertex, except tor the last one v, is being traversed at most oncc.Wc can thus uniquely charge each edge that we traverse to an unseen vertex, except the last vertexv, which is charged twice. Thus the overall number of charges is at most |V| + 1 =O(|V|), which is also the bound on the running time10.Quicksclcct has very poor worst-case performance. What can wc do about this? Quickselect has linear-time average-case performance, but quadratic-time worst-case performance. The standard solution is to keep track of the recursion depth, and switch to a linear-time worst-case selection algorithm if this depth exceeds some limit.11. Follow LCS algorithm to find the longest common subsequence of two words ABGKMR, BCGHM. The initial matrix is given below:12.Is the Knapsack problem, with integer capacityWand integer weights andvalues, fixed-parameter tractable in the parameterW?Yes, already because of the time boundO(nW).13.For a 0/1 knapsack problem, given n items, where each item has weight W and value V, find a set of items that could be put into the knapsack without over the capacity W of the knapsack. Assume that n=4, W={ 10,8,6,4}, V={5,4,3,2}, W=12。

算法分析与设计试题完整版

算法分析与设计试题完整版

算法分析与设计试题 HEN system office room 【HEN16H-HENS2AHENS8Q8-HENH1688】一、选择题(20分)1.最长公共子序列算法利用的算法是(B )。

A、分支界限法B、动态规划法C、贪心法D、回溯法2.实现棋盘覆盖算法利用的算法是(A )。

A、分治法B、动态规划法C、贪心法D、回溯法3.下面是贪心算法的基本要素的是(C )。

A、重叠子问题B、构造最优解C、贪心选择性质D、定义最优解4.回溯法的效率不依赖于下列哪些因素( D )A.满足显约束的值的个数B. 计算约束函数的时间C. 计算限界函数的时间D. 确定解空间的时间5.下面哪种函数是回溯法中为避免无效搜索采取的策略(B )A.递归函数 B.剪枝函数C。

随机数函数 D.搜索函数6.采用最大效益优先搜索方式的算法是(A )。

A、分支界限法B、动态规划法C、贪心法D、回溯法7.贪心算法与动态规划算法的主要区别是(B )。

A、最优子结构B、贪心选择性质C、构造最优解D、定义最优解8. 实现最大子段和利用的算法是(B )。

A、分治策略B、动态规划法C、贪心法D、回溯法9.优先队列式分支限界法选取扩展结点的原则是(C )。

A、先进先出B、后进先出C、结点的优先级D、随机10.下列算法中通常以广度优先方式系统搜索问题解的是(A )。

A、分支限界法B、动态规划法C、贪心法D、回溯法二、填空题(22分每空2分)1.算法是由若干条指令组成的有穷序列,且要满足输入、输出、确定性和有限性四条性质。

2、大整数乘积算法是用分治法来设计的。

3、以广度优先或以最小耗费方式搜索问题解的算法称为分支限界法。

4、舍伍德算法总能求得问题的一个解。

5、贪心选择性质是贪心算法可行的第一个基本要素,也是贪心算法与动态规划算法的主要区别。

6.快速排序template<class Type>void QuickSort (Type a[], int p, int r){if (p<r) {int q=Partition(a,p,r);QuickSort (a,p,q-1); 哈密顿环问题的算法可由回溯法设计实现。

《算法分析与设计》期末复习题

《算法分析与设计》期末复习题

一、选择题1.一个.java文件中可以有()个public类。

A.一个B.两个C.多个D.零个2.一个算法应该是()A.程序B.问题求解步骤的描述C.要满足五个基本特性D.A和C3.用计算机无法解决“打印所有素数”的问题,其原因是解决该问题的算法违背了算法特征中的()A.唯一性B.有穷性C.有0个或多个输入D.有输出4.某校有6位学生参加学生会主席竞选,得票数依次为130,20,98,15,67,3。

若采用冒泡排序算法对其进行排序,则完成第二遍时的结果是()A.3,15,130,20,98,67B.3,15,20,130,98,67C.3,15,20,67,130,98 D.3,15,20,67,98,1305.下列关于算法的描述,正确的是()A.一个算法的执行步骤可以是无限的B.一个完整的算法必须有输出C.算法只能用流程图表示D.一个完整的算法至少有一个输入6.Java Application源程序的主类是指包含有()方法的类。

A、main方法B、toString方法C、init方法D、actionPerfromed方法7.找出满足各位数字之和等于5的所有三位数可采用的算法思路是()A.分治法B.减治法C.蛮力法D.变治法8.在编写Java Application程序时,若需要使用到标准输入输出语句,必须在程序的开头写上( )语句。

A、import java.awt.* ;B、import java.applet.Applet ;C、import java.io.* ;D、import java.awt.Graphics ;9.计算某球队平均年龄的部分算法流程图如图所示,其中:c用来记录已输入球员的人数,sum用来计算有效数据之和,d用来存储从键盘输入的球员年龄值,输入0时表示输入结束。

图中空白处理框①和②处应填入的是()A.①sum ←sum + d B.①sum ←sum + c②c ←c + 1②c ←c + 1C.①sum ←sum + d D.①sum ←sum + c②d ←d + 1 ②d ←d + 110.报名参加冬季越野赛跑的某班5位学生的学号是:5,8,11,33,45。

《算法分析与设计》参考题1

《算法分析与设计》参考题1

1.简述算法和程序的区别。

算法:是指解决问题的一种方法或一个过程。

算法是若干指令的有穷序列,程序:是算法用某种程序设计语言的具体实现。

程序可以不满足算法的性质(4)。

例如:操作系统,是一个在无限循环中执行的程序,因而不是一个算法。

操作系统的各种任务可看成是单独的问题,每一个问题由操作系统中的一个子程序通过特定的算法来实现。

该子程序得到输出结果后便终止。

2.一个算法应有哪些主要特征?满足如下性质:(1)输入:有外部提供的量作为算法的输入。

(2)输出:算法产生至少一个量作为输出。

(3)确定性:组成算法的每条指令是清晰,无歧义的。

(4)有限性:算法中每条指令的执行次数是有限的,执行每条指令的时间也是有限的。

3.简述动态规划算法和贪心算法的基本要素。

动态规划算法的基本要素:最优子结构:矩阵连乘计算次序问题的最优解包含着其子问题的最优解。

这种性质称为最优子结构性质。

在分析问题的最优子结构性质时,所用的方法具有普遍性:首先假设由问题的最优解导出的子问题的解不是最优的,然后再设法说明在这个假设下可构造出比原问题最优解更好的解,从而导致矛盾。

利用问题的最优子结构性质,以自底向上的方式递归地从子问题的最优解逐步构造出整个问题的最优解。

最优子结构是问题能用动态规划算法求解的前提。

重叠子问题:递归算法求解问题时,每次产生的子问题并不总是新问题,有些子问题被反复计算多次。

这种性质称为子问题的重叠性质。

动态规划算法,对每一个子问题只解一次,而后将其解保存在一个表格中,当再次需要解此子问题时,只是简单地用常数时间查看一下结果。

通常不同的子问题个数随问题的大小呈多项式增长。

因此用动态规划算法只需要多项式时间,从而获得较高的解题效率贪心算法的基本要素:贪心选择性质:所谓贪心选择性质是指所求问题的整体最优解可以通过一系列局部最优的选择,即贪心选择来达到。

这是贪心算法可行的第一个基本要素,也是贪心算法与动态规划算法的主要区别。

动态规划算法通常以自底向上的方式解各子问题,而贪心算法则通常以自顶向下的方式进行,以迭代的方式作出相继的贪心选择,每作一次贪心选择就将所求问题简化为规模更小的子问题。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《算法分析与设计》试卷(A)
(时间90分钟满分100分)
一、填空题(30分,每题2分)。

1.最长公共子序列算法利用的算法是( B )。

A、分支界限法
B、动态规划法
C、贪心法
D、回溯法2.在对问题的解空间树进行搜索的方法中,一个活结点最多有一次机会成为活结点的是( B ).
A.回溯法
B.分支限界法
C.回溯法和分支限界法
D.回溯法求解子集树问题
3.实现最大子段和利用的算法是( B )。

A、分治策略
B、动态规划法
C、贪心法
D、回溯法4..广度优先是( A )的一搜索方式。

A、分支界限法
B、动态规划法
C、贪心法
D、回溯法5.衡量一个算法好坏的标准是( C )。

A 运行速度快
B 占用空间少
C 时间复杂度低
D 代码短
6.Strassen矩阵乘法是利用( A)实现的算法。

A、分治策略
B、动态规划法
C、贪心法
D、回溯法
7. 使用分治法求解不需要满足的条件是( A )。

A 子问题必须是一样的
B 子问题不能够重复
C 子问题的解可以合并
D 原问题和子问题使用相同的方法解
8.用动态规划算法解决最大字段和问题,其时间复杂性为( B ).
A.logn
B.n
C.n2
D.nlogn
9.解决活动安排问题,最好用( B )算法
A.分治
B.贪心
C.动态规划
D.穷举
10.下面哪种函数是回溯法中为避免无效搜索采取的策略( B )
A.递归函数 B.剪枝函数C。

随机数函数 D.搜索函数11. 从活结点表中选择下一个扩展结点的不同方式将导致不同的分支限界法,以下除( C )之外都是最常见的方式.
A.队列式分支限界法
B.优先队列式分支限界法
C.栈式分支限界法
D.FIFO分支限界法
12. .回溯算法和分支限界法的问题的解空间树不会是( D ).
A.有序树
B.子集树
C.排列树
D.无序树
13.优先队列式分支限界法选取扩展结点的原则是( C )。

A、先进先出
B、后进先出
C、结点的优先级
D、随机14.下面是贪心算法的基本要素的是( C )。

A、重叠子问题
B、构造最优解
C、贪心选择性质
D、定义最优解15.回溯法在解空间树T上的搜索方式是( A ).
A.深度优先
B.广度优先
C.最小耗费优先
D.活结点优先
二、填空题(20分,每空1分)。

1.算法由若干条指令组成的又穷序列,且满足输入、输出、
确定性和有限性四个特性。

2.分支限界法的两种搜索方式有队列式(FIFO)分支限界法、优先队列式分支限界法,用一个队列来存储结点的表叫活节点表。

3. 直接或间接调用自身的方法叫递归算法。

4、大整数乘积算法是用分治算法来设计的。

5、以广度优先或以最小耗费方式搜索问题解的算法称为分支限界法。

6.动态规划的子问题重叠。

7.贪心算法的选择性质是贪心选择性质、动态规划法的选择性质是最优子结构性质。

8.问题的最优子结构性质是该问题可用动态规划算法或贪心算法求解的关键特征。

9.以深度优先方式搜索问题解的算法称为回溯法。

10、快速排序法的三个步骤为:分解、递归求解、
合并。

11、贪心算法的基本要素是贪心选择性质和最有子结构性质性质。

三、问答题(30分,每题6分)。

1.计算下列函数的渐进表达式(1)n2
10
/
n2 (2)10log3n; (3) 21+1/n;
(1)O(2n) (2)O(n)/ O(logn) (3)O(1) 2.解释什么是NP类问题。

NP问题是指还未被证明是否存在多项式算法能够解决的问题,而其中NP完全问题又是最有可能不是P问题的问题类型。

所有的NP问题都可以用多项式时间划归到他们中的一个。

所以显然NP完全的问题具有如下性质:它可以在多项式时间内求解,当且仅当所有的其他的NP-完全问题也可以在多项式时间内求解。

3.动态规划法的4个步骤设计是什么?
(1)找出最优解的性质,并刻画其结构特征;
(2).递归地定义最优值;
(3)以自底向上的方式计算出最优值;
4.用回溯法解题通常包含几个步骤?
(1)针对所给问题,定义问题的解空间;
(2)确定易于搜索的解空间结构;
(3)以深度优先方式搜索解空间,并在搜索过程中用剪枝函数避免无效搜索。

5 简述分支限界法与回溯法的异同点。

相同点:二者都是一种在问题的解空间树T上搜索问题解的算法。

不同点:1.在一般情况下,分支限界法与回溯法的求解目标不同。

回溯法的求解目标是找出T中满足约束条件的所有解,而分支限界法的求解目标则是找出满足约束条件的一个解,或是在满足约束条件的解中找出使某一目标函数值达到极大或极小的解,即在某种意义下的最优解。

2.回溯法与分支-限界法对解空间的搜索方式不同,回溯法通常采用尝试优先搜索,而分支限界法则通常采用广度优先搜索。

3.对节点存储的常用数据结构以及节点存储特性也各不相同,除由搜索方式决定的不同的存储结构外,分支限界法通常需要存储一些额外的信息以利于进一步地展开搜索
26分,1题11分,2题15分)。

阅卷人得分
用动态规划策略求解最长公共子序列问题:
(1)给出计算最优值的递归方程。

(2)给定两个序列X={B,C,D,A },Y={A,B,C,B},请采用动态规划策略求出其最长公共子序列,要求给出过程。

(1)
引进一个二维数组c[][],用c[i][j]记录X[i]与Y[j] 的LCS 的长度,b[i][j]记录c[i][j]是通过哪一个子问题的值求得的,以决定搜索的方向。

我们是自底向上进行递推计算,那么在计算c[i,j]之前,c[i-1][j-1],c[i-1][j]与c[i][j-1]均已计算出来。

此时我们根据X[i] = Y[j]还是X[i] != Y[j],就可以计算出c[i][j]。

问题的递归式写成:
(2)(2)
YABCB
X0000
B0011 1
C0012 2
D00 1 2 2
A0 1 1 2 2 最长公共子序列:{BC}。

相关文档
最新文档