浙大数据结构期末考试2007-2008
07-08数据结构试题和答案
07-08数据结构试题和答案浙江⼤学2007–2008学年秋季学期《数据结构基础》课程期末考试试卷开课学院:软件院、计算机、竺可桢学院,考试形式:闭卷,允许带_ ⽆⼊场考试时间:_2007_年_11_⽉_17⽇, 所需时间:120 分钟考⽣姓名: ___学号:专业: ____教师:Answer SheetNOTE: Please write your answers on the answer sheet.注意:请将答案填写在答题纸上。
I. Please select the answer for the following problems. (20 points)(1)The time complexity of the following piece of code is (2 points) for(i=0; ifor(j=i; j>0; j/=2)printf(“%d\n”, j);a. O(n)b. O(n*n)c. O(nlogn)d. O(n*i)(2)Suppose that the time complexities of two programs are given by T1(N)=O(f(N))and T2(N)=O(f(N)). Which of the following equations is true? (2 points) a. T1(N)+T2(N)=O(f(N)) b. T1(N)-T2(N)=o(f(N))c. T1(N)/T2(N)=O(1)d. T1(N)=O(T2(N))(3)Given an empty stack S and an empty queue Q. A list of characters are pushedinto S in the order of a, b, c, d, e, f and every character that is popped from S will be inserted into Q immediately. If the output of Q is b, d, c, f, e, a, the minimum capacity of S must be . (2 points)a. 6b. 5c. 4d. 3(4)Suppose that the size of a hash table is 11, and the hash function isH(key)=key%11. The following 4 elements have been inserted into the table as Addr(14)=3, Addr(38)=5, Addr(61)=6,Addr(86)=9. When open addressing with quadratic probing is used to solve collisions, the address of the element withkey=49 will be . (2 points)a. 4b. 7c. 8d. 10(5)For a binary tree, given the postorder traversal sequence FDEBGCA and theinorder traversal sequence FDBEACG, the corresponding preorder traversal sequence is . (2 points)a. ABDFEGCb. ABDEFCGc. ABDFECGd. ABCDEFG(6)Insert 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, 2 into an initiallyempty binary min heap one at a time, after performing three DeleteMin operations, the last element of the heap is . (2 points)a. 10b. 11c. 8d. 5(7)Let T be a tree created by union-by-size with N nodes, then the height ofT can be . (2 points)a. at most log2(N)+1b. at least log2(N)+1c. as large as Nd. anything that is greater than 1(8)Given a weighted and connected undirected graph G, there is/are minimumspanning tree(s) of G. (2 points)a. only oneb. one or morec. more than oned. zero or more(9)To find the shortest path between a pair of given vertices, methodcan be used. (2 points)a. Kruskalb. Dijkstrac. Hashingd. Critical Path(10)Among the following sorting algorithms, has the average run timeO(NlogN) with O(N) extra spaces. (2 points)a. Quick sortb. Heap sortc. Merge sortd. Insertion sortII. Given the function descriptions of the following three (pseudo-code) programs, please fill in the blank lines. (24 points) (1)The function is to delete the maximum element in a max heap. (12 points) ElementType DeleteMax( PriorityQueue H ) {int i, Child;ElementType MaxElement, LastElement;MaxElement = ① ;LastElement = H->Elements[ H->Size-- ];for( i = 1; i * 2 <= H->Size; i = Child ){ Child = i * 2;if( ② )Child++;if( LastElement < H->Elements[ Child ] )③ ;else break;}H->Elements[ i ] = LastElement;return MaxElement;}(2)The function is to sort a list of N elements A[] in non-decreasing orderby Shellsort with Shell’s increments. (6 points)void Shellsort( ElementType A[ ], int N ){int i, j, Increment;ElementType Tmp;for ( Increment = N / 2; Increment > 0; Increment /= 2 )for ( i = Increment; i < N; i++ ) {Tmp = A[ i ];for ( j = i; ① ; j - = Increment )if(② )A[ j ] = A[ j - Increment ];else break;A[ j ] = Tmp;}}(3)The function is to find maximum sum value of the subsequence in A[0], A[1], A[2], … A[N-1]. (6 points)int MaxSubsequenceSum(int A[], int N){int ThisSum, MaxSum, j;ThisSum=MaxSum=0;for(j=0; jThisSum = ① ;if (ThisSum >MaxSum)MaxSum= ThisSum;else if (ThisSum <0)② ;}return MaxSum;}III. Please write or draw your answers for the following problems on the answer sheet.(41 points)(1)Please list:(a)the depth-first search sequence;(b)(c)the minimum spanning tree.Note: All the adjacent vertices are to be visited by alphabetical order.(15 points)(2)Insert the numbers 40, 28, 6, 72, 100, 3, 80, 91, 38 into an initially emptybinary search tree. Please show(a)the resulting binary search tree; (10 points) and(b)the resulting binary search tree after 72 is deleted. (3 points)(3)The array representation of the disjoint sets is given by { 2, –4, 2, 2,-3, 5, 6, 9, -2 }. Please list the resulting array elements after invokingUnion(7, 9) with union-by-size. Keep in mind that the elements are numberedfrom 1 to 9. (5 points)(4)Given a list of N elements and an integer k. Please describe two differentalgorithms for finding the kth largest element and give the time complexities.(8 points)IV. If each vertex in an undirected weighted graph has a number of balloons assigned.Explain how to modify Dijkstra's algorithm so that if there is more than one minimum path from v to w, a path with the maximum number of balloons is chosen.(15 points)Note : T[ V ].balloon contains the number of balloons at vertex V.void Dijkstra( Table T )。
《数据结构》期末考试试卷试题及答案
《数据结构》期末考试试卷试题及答案第一部分:选择题(每题2分,共20分)1. 下面哪个数据结构是线性结构?A. 树B. 图C. 队列D. 网络流2. 下面哪个数据结构用于实现广度优先搜索算法?A. 栈B. 队列C. 散列表D. 堆3. 下面哪个数据结构用于实现深度优先搜索算法?A. 栈B. 队列C. 散列表D. 堆4. 下面哪个数据结构用于实现快速排序算法?A. 栈B. 队列C. 散列表D. 堆5. 下面哪个数据结构用于实现优先队列?A. 栈B. 队列C. 散列表D. 堆6. 下面哪个数据结构用于实现哈希表?A. 栈B. 队列C. 散列表D. 堆7. 下面哪个数据结构用于实现最小树算法?A. 栈B. 队列C. 散列表D. 堆8. 下面哪个数据结构用于实现拓扑排序算法?A. 栈B. 队列C. 散列表D. 堆9. 下面哪个数据结构用于实现最短路径算法?A. 栈B. 队列C. 散列表D. 堆10. 下面哪个数据结构用于实现并查集算法?A. 栈B. 队列C. 散列表D. 堆第二部分:填空题(每题2分,共20分)1. 链表是一种______数据结构。
2. 二叉树的节点最多有______个子节点。
3. 堆是一种特殊的______。
4. 散列表的查找效率取决于______。
5. 图的遍历算法包括______和______。
6. 快速排序算法的平均时间复杂度为______。
7. 哈希表中的冲突解决方法有______和______。
8. 最小树算法包括______和______。
9. 最短路径算法包括______和______。
10. 并查集算法用于解决______问题。
第三部分:简答题(每题10分,共50分)1. 请简述栈和队列的区别。
2. 请简述二叉搜索树的特点。
3. 请简述哈希表的原理。
4. 请简述图的深度优先搜索算法。
5. 请简述最小树算法的原理。
第四部分:编程题(每题20分,共50分)1. 编写一个函数,实现链表的插入操作。
数据结构07年(下)试卷B
__________________学院__________级___________班 姓名_______________ 学号_______________………………………………(密)………………………………(封)………………………………(线)………………………………密 封 线 内 答 题 无 效2007-2008学年度第二学期期末考试数据结构试卷 B 卷答卷说明:1.本试卷共9页,五个大题,满分100分,120分钟完卷。
2.本试卷为闭卷考试,请将所有题目直接做在试卷上。
一、单项选择题(每题21.单循环链表的尾结点的指针域的值为( )。
A) NULL B) 0 C) 首结点地址 D) 尾结点地址2.设有一个足够大的栈,入栈元素的顺序为wxyz,,则栈的可能输出序列是( )。
A )zwyx B )ywxz C )wxyz D )zxyw3.设串s1=’ABCDEFG’,s2=’PQRST’,函数con(x,y)返回x 和y 串的连接串,subs(s, i, j)返回串s 的从序号i 开始的j 个字符组成的子串,len(s)返回串s 的长度,则con(subs(s1, 2, len(s2)), subs(s1, len(s2), 2))的结果串是: A) BCDEF B) BCDEFG C) BCPQRST D) BCDEFEF4.若广义表A=((a,b,c),(d,e,f )),则式子GetHead(GetTail(GetHead(GetTail(A))))的值为()。
A )(a,b,c )B )(d,e)C )eD )f5.下列程序段的时间复杂度是()。
i=1;while (i<=n) i*=2;A)O(1) B)O(㏒2n) C)O(n) D)O(n2)6.已知一算术表达式的中缀形式为A+B*C-D/E,后缀形式为ABC*+DE/-,其前缀形式为()。
A)–A+B*C/DE B)–A+B*CD/EC)–+*ABC/DE D)–+A*BC/DE7.假设有60行70列的二维数组a[1…60, 1…70]以列序为主序顺序存储,其基地址为10000,每个元素占2个存储单元,那么第32行第58列的元素a[32,58]的存储地址为()。
《数据结构》期末考题(doc 8页)
《数据结构》期末考题(doc 8页)西南财经大学2007 - 2008 学年第二学期统计专业本科 2007、2006级(二、三年级上学期)学号评定成绩(分)学生姓名担任教师周启海《数据结构》期末考试题(B卷)(下述一—三题全作计100分,两小时完卷)考试日期:2008. 12 . 24试题全文:遵守考场纪律,防止一念之差贻误终生。
一、判断题(每小题5分,共10分)1. “广义表”,难用顺序存储结构来描述。
答:2. 已知排序所采用的数据结构、算法思想、语言环境等均相同。
如果对同一组待排序数据,则其递增序排序算法与递减排序算法的运行时间通常不同。
答:二、简答题(每小题5分,共60分)1. 有人说:“学习《数据结构》课程的关键,可概括为——什么是‘数据结构’?有哪些‘数据结构’?各种‘数据结构’特点如何?(所论问题)该用何种‘数据结构’?”这种说法错吗?为什么?答:5. “二叉树”的存储结构,虽然既可采用顺序存储结构(例如数组),也可采用非顺序存储(例如链表)。
但为什么说“非完全二叉树,不宜采用顺序存储结构”?答:6. 设计××××航空公司××航班的“飞机乘客票务管理程序”时,最适宜采用的数据结构是什么?为什么?答:7.现有实现同一功能的三个算法A1,A2和A3,且已知其时间复杂度顺次为Tl=O(2n),T2=O(n2),T3=O(n log n)。
请仅就其时间复杂度,给出各算法优化程度递增的顺序,并说明理由。
答:8. 已知有 5 个元素的入栈次序为“A,B,C,D,E”。
现要求第一个出栈元素为C、第二个出栈元素为D,而其余栈元素仍须保留在此栈中。
请说明相关栈及其元素的弹出与压入操作处理过程。
答:9. 已知二叉树含三个结点A、B、C,请给出以B为根结点的二叉树所有形态。
答:10. 设二维数组A[10][8]的每个数组元素占四个存储单位,且第一个元素A[1][1]的存储地址为1000。
浙江大学城市学院2007《计算机网络》答案A
浙江大学城市学院2007 — 2008 学年第一学期期末考试《计算机网络》A卷参考答案及评分细则一、填空题(每题__1__分,共__10__分)1.(网络)2.(无编号帧)3.(同步)4.( UDP )5.(全双工)6.(MAC/介质访问控制)7.(anonymous)8.()9.(时分)10.(包过滤路由器)二、单项选择题(每题__1__分,共__30__分)1.(C )2.(A )3.(D )4.(C )5.(B )6.(C )7.(A )8.(D )9.(C )10.(D )11.(C )12.(D )13.(D )14.(B )15.(C )16.(D )17.(D )18.(B )19.(C )20.(A )21.(D )22.(A )23.(C )24.(B )25.(B )26.(C )27.(A )28.(B )29.(C )30.(B )三、问答与计算题(本大题共__6__题,共__36__分)1.(6分)计算机网络采用层次结构的模型有什么好处?请画出OSI参考模型和TCP/IP参考模型的层次结构图。
答:计算机网络中采用层次结构,是为了将复杂的网络问题分解成许多较小的、较容易处理的部分来处理,以便于学习、理解和设计计算机网络。
分层的设计有以下好处:①各层之间相互独立,高层并不需要知道低层如何实现;②灵活性好,当任何一层发生变化时,其他层并不受影响;③各层都可以采用最合适的技术来实现;④易于实现和维护;⑤有利于促进标准化。
(2分)OSI参考模型分为七层(2分),TCP/IP参考模型共有四层结构(2分),如图所示:评分标准:OSI参考模型和TCP/IP参考模型层次描述完整正确各得2分,若有部分错,酌情扣1-2分。
2.(6分)在下列空白处填上数字(1至6),表示在源结点的一个用户发送信息到目标结点的一个用户所发生事件的顺序。
____3____ 当信息通过源结点时,每一层都加上控制信息____1____ 在源结点的网络用户产生信息____6____ 在目标结点的网络用户接受信息____5____ 信息向上通过目标结点的各个网络层次,每一层都除去它的控制信息____4____ 信息以电信号的形式通过物理链路发送____2____ 信息传给源结点的最高层(应用层)评分标准:答错一项扣1分。
数据结构20071期末试卷a卷
期末考试试卷(A)卷2007 ——2008 学年第一学期课程名称:数据结构适用年级/专业: 06/计应、计教试卷类别开卷()闭卷(√)学历层次本科考试用时 120分钟《.考生.......................》...注意:答案要全部抄到答题纸上,做在试卷上不给分一、单项选择(每小题2分,共20分)()1.算法的计算量的大小称为计算的()。
A.可读性 B. 复杂性 C. 现实性 D. 难度()2.链接存储的存储结构所占存储空间:A.分两部分,一部分存放结点值,另一部分存放表示结点间关系的指针B.只有一部分,存放结点值C.只有一部分,存储表示结点间关系的指针D.分两部分,一部分存放结点值,另一部分存放结点所占单元数()3.对于顺序存储的线性表,访问结点和删除结点的时间复杂度为()。
A.O(n) O(n) B. O(n) O(1) C. O(1) O(n) D. O(1) O(1) ()4.设有4个数据元素a1、a2、a3和a4,对他们进行队操作,在进队操作时,按a1、a2、a3、a4次序每次进入一个元素。
假设队的初始状态是空,进队两次,出队一次,再进队两次,出队一次;这时,第一次出队得到的元素是()A.a1 B. a2 C. a3 D. a4()5.有一个100*90的稀疏矩阵,非0元素有10个,设每个整型数占2字节,则用三元组表示该矩阵时,所需的字节数是()。
A.10B. 66C. 18000D. 33 ()6.串的长度是指()A.串中所含不同字母的个数 B.串中所含字符的个数C.串中所含不同字符的个数 D.串中所含非空格字符的个数()7.设森林F中有三棵树,第一,第二,第三棵树的结点个数分别为M1,M2和M3。
与森林F对应的二叉树根结点的右子树上的结点个数是()。
A.M1 B.M1+M2 C.M3 D.M2+M3()8.用邻接表表示图进行广度优先遍历时,通常是采用来实现算法的。
A.栈 B. 队列 C. 树 D. 图()9.在表长为n的链表中进行线性查找,它的平均查找长度为A. ASL=n;B. ASL=(n+1)/2;C. ASL=n+1;D. ASL≈log2(n+1)-1()10.下列关键字序列中,()是堆。
浙江师范大学数据结构期末试卷
浙江师范大学《数据结构与算法分析》期末试卷(2006-2007学年第一学期)考试类型:闭卷使用学生:数理与信息工程学院学生考试时间:120分钟出卷时间:2007年1月10日班级:__________ 学号:__________ 姓名:____________说明:考生应将全部答案写在答题纸上,否则作无效处理一、单项选择题(每小题2分,共40分)1.数据结构的二元组定义DS={D,S}中,D是数据元素的有限集合,而S是D上_______的有限集合。
A、数据B、数据项C、关系D、操作2.下列有关线性表的叙述中,正确的是________。
A、线性表中的元素之间是线性关系B、线性表中至少有一个元素C、线性表中任何一个元素有且仅有一个直接前驱D、线性表中任何一个元素有且仅有一个直接后继3.栈和队列都是操作受限的线性表,他们各自的特点是。
A、栈:后进先出,队列:先进后出B、栈:先进后出,队列:后进后出C、栈:后进后出,队列:先进先出D、栈:先进先出,队列:后进先出4.下列关于串的叙述中,正确的是。
A、一个串的字符个数即该串的长度B、一个串的长度至少是1C、空串是由一个空格组成的串D、两个串S1和S2若长度相同,则这两个串相等。
5.若一棵二叉树具有10个度为2的结点,则该二叉树的度为0的结点个数是。
A 、9B 、12C 、11D 、不确定6.高度为k的二叉树(仅含根结点的二叉树高度为1)的结点数最多是________多少个。
A、 2K-1-1B、 2K-1C、 2K+1-1D、 2K+17.一棵二叉排序树T,用方法进行遍历,可以得到结点键值的递增序列。
A、先序遍历B、后序遍历C、层序遍历D、中序遍历8.下面选项中符合堆的定义是 _____ 。
A、100 86 48 73 35 39 42 57 66 21B、12 70 33 65 24 56 48 92 86 33C、5 56 23 40 38 29 31 35 76 28 100D、66 92 56 38 66 23 42 12 30 529.设有一个长度为100的已排好序的线性表,用二分查找进行查找,若查找不成功,至少比较次。
浙江大学城市学院07-08操作系统试卷
4. 检测死锁的算法是在______。 A、程序中申请资源时使用 C、死锁即将出现时使用
B、死锁出现之后使用 D、定时检查系统状态时使用
5. 指出以下非临界资源______。
A、纯代码
B、变量
C、队列
D、栈
6. 分区式存储器管理方式中,每个程序______ 。
A、一定在分区中连续、部分存放
B、一定在分区中连续、整体存放
进程 到达时间 运行时间 完成时间 周转时间 平均周转时间 7. (6 分) 最短查找时间优先算法(SSTF)
A、有序文件
B、记录式文件
C、顺序文件
D、流式文件
19. 逻辑文件是______的文件组织形式。 A、在外部设备上 B、从用户观点看
C、虚拟存储
D、目录
20. ______的物理结构对文件随机存取时必须按指针进行,效率较低。
A、连续文件
B、链接文件
C、索引文件
D、多级索引文件
二.判断题(本大题共 15 题,每题 1 分,共 15 分。) 1. 进程被阻塞以后,代表进程在阻塞队列的是它的进程控制块。 2. 所谓并行是指两个或两个以上的事件在同一时刻发生。 3. 一个进程从等待态变成就绪态必定会引起进程切换。 4. 对临界资源,应采用互斥访问方式来实现共享。 5. 处于死锁的系统中,没有进程可再运行。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 四.简答题(本大题共6题,共 40 分。) 得分 1. (3 分)请在下表中正确的位置打勾。
时间换取空间的技术 空间换时间的技术 快表 分页存储 交换技术 虚拟存储器 索引顺序文件 层次存储体系 2. (6 分)试简要回答有哪些磁盘性能参数?并请写出磁盘平均访问时间和这些参数的关系。
高级数据结构与算法分析 试卷答案
浙江大学2006–2007学年秋季学期《高级数据结构与算法分析》课程期末考试试卷开课学院:软件学院、计算机学院、竺可桢学院,考试形式:闭卷,允许带_ 无入场考试时间:_2007_年_1_月_16_日, 所需时间: 120 分钟考生姓名: ___学号:专业: ____教师:NOTE: Please write your answers on the answer sheet.注意:请将答案填写在答题纸上。
I. Please fill in the blanks ( There could be multiple answers for one blank ). (24points) Note: Zero point for a blank selection since there is at least one answer for each problem.(1)The time complexity for finding an element in a splay tree with N nodesis C (or b – not worst case) . (2 points)a. O(1)b. O(log N)c. O(N)d. O(N log N)(2)The depth of an AVL tree with 32 nodes is at least b (2 points) andat most c .(2 points)a. 5b. 6c. 7d. 8(3)When solving the bin packing problem with the best-fit method, arrangingthe remaining capacities of the bins in b (2 points) can reduce the time complexity.a. a linear sequential storageb. an AVL treec. a min-heapd. an ordered linear storage(4) A binomial queue of size 53 can be represented by the following binomialqueues d . (2 points)a. B0 B1 B2 B3 B4 B5b. B0 B1 B3 B5c. B1 B3 B5 B6d. B0 B2 B4 B5(5) A leftist tree with r nodes on the right path must have a nodes.(2(6)For a binomial queue, (b) d take(s) a constant time on average. (2points)a. mergingb. find-minc. delete-mind. insertion(7)Which of the following problems are not known to be run in polynomial time:b d .(2 points)a. Euler circuit problemb. Hamilton cycle problemc. Single-source unweighted shortest-path problemd. Single-source unweighted longest-path problem(8)An amortized time bound is b d . (2 points)a. >= worst-case time boundb. >= average-case time boundc. <= best-case time boundd. <= worst-case time bound(9)To solve a problem with input size N by divide and conquer algorithms, ifthe conquer step takes O(N) extra work to form the solution from thesub-solutions, then among the following four dividing methods, b (2points) is the best one while a (2 points) is the worst one.a. divide into 4 sub-problems of equal complexity N/3b. divide into 3 sub-problems of equal complexity N/4c. divide into 4 sub-problems of equal complexity N/4d. divide into 3 sub-problems of equal complexity N/3(10)The fastest algorithm for constructing an optimal binary search tree isthe c . algorithm. (2 points)a. greedyb. divide and conquerc. dynamic programmingd. backtracking II. Given the function descriptions of the following two (pseudo-code) programs, please fill in the blank lines. (15 points) 每个3分(1) The function is to merge two equal-sized binomial trees T1 and T2. (6 points) BinTree CombineTrees( BinTree T1, BinTree T2 ){if ( T1->Element > T2->Element )return CombineTrees( T2, T1 );T2->NextSibling = ①T1->LeftChild;②T1->LeftChild = T2;return T1;}注意:不叫LeftChild也算对。
《数据结构》期末考试试题及答案
《数据结构》期末考试试题及答案一、选择题(每题2分,共20分)1. 下列哪一个不是线性结构的基本特征?A. 有且只有一个根结点B. 每个结点最多有一个前驱和一个后继C. 有且只有一个叶子结点D. 有序对中第一个元素是根结点答案:C2. 在单链表中,存储元素的数据域称为元素的哪个部分?A. 指针域B. 数据域C. 结点域D. 头结点答案:B3. 在顺序存储结构中,数据元素之间的逻辑关系由哪个因素决定?A. 数据元素的存储顺序B. 数据元素的存储位置C. 数据元素的类型D. 数据元素的大小答案:A4. 下列哪种排序算法的时间复杂度不是O(nlogn)?A. 快速排序B. 归并排序C. 堆排序D. 冒泡排序答案:D5. 在二叉树中,具有度为2的结点的个数是n0,度为0的结点个数是n2,则有()。
A. n0 = n2 - 1B. n0 = n2 + 1C. n0 = n2D. n0 = n2 + 2答案:B6. 在线索二叉树中,哪个结点被称为线索结点?A. 有左子树的结点B. 有右子树的结点C. 既没有左子树也没有右子树的结点D. 具有左右子树的结点答案:C7. 在双向链表中,查找结点的时间复杂度是()。
A. O(1)B. O(n)C. O(nlogn)D. O(n^2)答案:B8. 在栈的操作中,下列哪个操作是非法的?A. 先进先出B. 后进先出C. 可以插入任意元素D. 可以删除任意元素答案:D9. 在顺序表中进行插入操作时,平均移动次数为()。
A. 0B. n/2C. nD. n-1答案:C10. 在下列排序算法中,哪个算法是不稳定的?A. 冒泡排序B. 快速排序C. 插入排序D. 归并排序答案:B二、填空题(每题2分,共20分)1. 线性表的顺序存储结构称为顺序表,其基本特点是()。
答案:元素顺序存储2. 在单链表中,每个结点包括两个域:数据域和()。
答案:指针域3. 在二叉树中,度为0的结点称为(),度为2的结点称为()。
数据结构期末考试试题(含答案)
数据结构期末考试试题(含答案)数据结构期末考试试题(含答案)第一题:多项式相加(20分)将两个多项式 P(x) 和 Q(x) 相加,结果存储在另一个多项式 S(x) 中,请写出相应的算法,并给出其时间复杂度分析。
答案:算法如下:1. 初始化一个空多项式 S(x)。
2. 分别取多项式 P(x) 和 Q(x) 的第一项,判断指数的大小关系,并将指数较小的项加入 S(x)。
3. 若指数相同,则将两项系数相加,并将结果加入 S(x)。
4. 重复步骤2和步骤3,直到两个多项式中的所有项都被处理完。
5. 返回结果多项式 S(x)。
时间复杂度分析:- 假设 P(x) 和 Q(x) 的项数分别为 m 和 n。
- 在最坏情况下,需要比较 m+n 次指数大小,并进行 m+n-1 次系数相加。
- 因此,该算法的时间复杂度为 O(m+n)。
第二题:循环队列设计(30分)请设计一个循环队列,实现入队、出队等基本操作,并给出时间复杂度分析。
答案:定义循环队列的结构体如下:```ctypedef struct {int *data; // 存储队列元素的数组int front; // 队首指针,指向队首元素的位置int rear; // 队尾指针,指向队尾的下一个位置int maxSize; // 队列的最大容量} CircularQueue;```基本操作的实现如下:1. 初始化循环队列:```cvoid initQueue(CircularQueue *queue, int maxSize) {queue->data = (int *)malloc(sizeof(int) * maxSize);queue->front = queue->rear = 0;queue->maxSize = maxSize;}```2. 入队操作:```cint enqueue(CircularQueue *queue, int value) {if ((queue->rear + 1) % queue->maxSize == queue->front) { return 0; // 队列已满,插入失败}queue->data[queue->rear] = value;queue->rear = (queue->rear + 1) % queue->maxSize;return 1; // 插入成功}```3. 出队操作:```cint dequeue(CircularQueue *queue, int *value) {if (queue->front == queue->rear) {return 0; // 队列为空,出队失败}*value = queue->data[queue->front];queue->front = (queue->front + 1) % queue->maxSize; return 1; // 出队成功}```时间复杂度分析:- 入队和出队操作的时间复杂度均为 O(1)。
算法数据结构考卷(B)
第2页共4页19. n 条边的无向图的邻接表的存储中,边结点的个数有() A .n B .2n C .n/2 D. n*n 20.顺序查找适合于存储结构为()的线性表 A. 哈希存储 B.压缩存储 C.顺序存储或链表存储 D.索引存储二.判断题(本大题共10小题,每小题1分,共10分)请在每小题的括号中填上正确答案。
错填、不填均无分。
1. 在线性表的链式存储结构中,逻辑上相邻的元素在物理位置上不一定相邻。
( )2. 若采用三元组压缩技术存储稀疏矩阵,只要把每个元素的行下标和列下标互换,就完成了对该矩阵的转置运算( )3. 插入排序是稳定的,希尔排序是不稳定的。
( )4. .二叉树中的叶子结点就是二叉树中没有左右子树的结点。
( )5. 有向图的邻接表和逆邻接表中的结点数一定相同。
( )6. 用相邻矩阵表示图所用的存储空间大小与图的边数成正比。
()7. 霍夫曼树一定是满二叉树。
()8. 栈是一种线性结构。
()9. 求最小生成树的Prim 算法在边较少,节点较多时效率高。
()10. 对二叉排序树进行中序遍历得到的序列是由小到大有序的。
( ) 三、填空题(本大题共10小题,每小题2分,共20分)请在每小题的空格中填上正确答案。
错填、不填均无分。
1. 在一个单链表中p 所指结点之后插入一个由指针f 所指结点,应执行s->next=________;和p->next=s 的操作。
2. 在一个长度为n 的循环链表中,删除其元素值为x 的结点的时间复杂度为_____。
3. 假设以行优先顺序存储三维数组A[5][6][7],其中元素A[0][0][0]的地址为1100,且每个元素占2个存储单元,则A[4][3][2]的地址是________。
4. 深度为k(k>0)的二叉树最多有___________个结点。
5. 串中所含字符个数称为该串的_____ ______。
6. n(n>0)个结点、(n-1)条边的连通无向图中,顶点度数最大值为____________。
数据结构期末考试试题及答案
数据结构期末考试试题及答案一、选择题(每题2分,共20分)1. 在数据结构中,线性结构的特点是什么?A. 元素之间存在一对一的关系B. 元素之间存在一对多的关系C. 元素之间存在多对多的关系D. 元素之间存在一对一或多对多的关系2. 栈(Stack)是一种特殊的线性表,其特点是:A. 允许在表的任一位置进行插入和删除操作B. 只能在表的首端进行插入和删除操作C. 只能在表的末端进行插入和删除操作D. 插入和删除操作没有特定的限制3. 以下哪个算法是排序算法?A. 快速排序B. 深度优先搜索C. 广度优先搜索D. 二分查找4. 哈希表解决冲突的常用方法不包括:A. 开放寻址法B. 链地址法C. 二分查找法D. 再散列法5. 在图的遍历算法中,深度优先搜索(DFS)使用的是:A. 栈B. 队列C. 链表D. 树...(此处省略其他选择题)二、简答题(每题10分,共30分)1. 请简述二叉树的三种遍历方法及其特点。
2. 什么是平衡二叉树?请说明它与普通二叉树的区别。
3. 解释什么是图的邻接矩阵表示法和邻接表表示法,并比较它们的优缺点。
三、计算题(每题15分,共30分)1. 给定一个数组A[1...n],请写出一个时间复杂度为O(n)的算法,找出数组中的最大值和最小值。
2. 假设有一个链表,链表中的节点按照值递增的顺序排列,请设计一个算法删除链表中所有重复的节点。
四、编程题(每题20分,共20分)1. 编写一个函数,实现二叉搜索树的插入操作,并保证树的平衡。
数据结构期末考试答案一、选择题1. C2. B3. A4. C5. A...(此处省略其他选择题答案)二、简答题1. 二叉树的三种遍历方法包括前序遍历、中序遍历和后序遍历。
前序遍历首先访问根节点,然后递归遍历左子树,最后递归遍历右子树。
中序遍历首先递归遍历左子树,然后访问根节点,最后递归遍历右子树。
后序遍历首先递归遍历左子树,然后递归遍历右子树,最后访问根节点。
浙大数据结构期末考试2008-2009
(7) Given an integer sequence { 2 6 11 8 4 5 3 12 1 7 10 9 }. The
sorting method which takes the most extra space is ____ (2 points)
a. insertion sort
b. Shellsort
(2 points)
a. n-1
b. n
c. n+1
d. n(n+1)/2
(9) A strongly connected graph with n vertics has at least ______
edges (2 points)
a. n(n-1)
b. n-1
c. n
d. n+1
(10)
Given a weighted graph G. Among the following statements, ______ is true. (2 points) a. Let T be a minimum spanning tree of G. Then the path in T
#define leftchild(i) ( 2*(i)+1 )
void PercDown( ElementType A[ ], int i, int N )
{ int child;
ElementType Tmp;
for ( Tmp = A[i]; leftchild(i) < N; I = child ) {
void Dijkstra( Table T )
{ /* T[v].Count stores the number of edges on the path from the source to v, */
浙江大学2007–2008学年春季学期
浙江大学2007–2008学年春季学期《软件工程》课程期末考试试卷开课学院:计算机学院 ,考试形式:开卷,允许带1本正式出版的参考书入场 考试时间:2008年4月18日,所需时间:120分钟,任课教师:考生姓名: _ __ 学号: 专业: ____ 题序 一 二 三 四 总 分 得分评卷人I. Please select the correct answers and fill in the answer sheet: (20 pts.)Note: Zero point for a blank selection since there is at least one answer for each problem.1. Which question no longer concerns the modern software engineer?A) Why does computer hardware cost so much?B) Why does software take a long time to finish?C) Why does it cost so much to develop a piece of software?D) Why can't software errors be removed from products prior to delivery?2. How does a software project manager need to act to minimize the risk of software failure?A) double the project team sizeB) request a large budgetC) start on the right footD) track progress3. What does the system specification describe?A) functions of a computer-based systemB) implementation of each allocated systemC) performance and constraints of the systemD) time required for system simulation4. Which of these are goals for WebE requirements gathering?A) Define user interaction scenariosB) Identify WebApp development toolsC) Determine performance constraintsD) Identify content requirements5. The criteria used to assess the quality of an architectural design should be based on system .A) accessibilityB) controlC) dataD) implementation6. The OO testing integration strategy involves testingA) groups of classes that collaborate or communicate in some wayB) single operations as they are added to the evolving class implementationC) operator programs derived from use-case scenariosD) none of the above7. Which of these activities is not one of the activities recommended to be performed by an independent SQA group?A) prepare SQA plan for the projectB) review software engineering activities to verify process complianceC) report any evidence of noncompliance to senior managementD) serve as the sole test team for any software produced8. As the WebApp architecture is constructed which types of testing are used as integration tests?A) Component testingB) Content testingC) Navigation testingD) Usability testing9 Which of the following tasks are part of software configuration management?A) change controlB) statistical quality controlC) reportingD) version control10. Software risk always involves two characteristicsA) fire fightingB) lossC) uncertaintyD) crisis managementII. Please specify “T” (true) or “F” (false) for the following statements and fill in the answer sheet. (10 pts.)1.It is generally accepted that one cannot have weak software processes and create high quality endproducts.2.Because there are many factors to consider in any design effort, all design should be as complex aspossible.ponents should be loosely coupled to one another and to the external environment.4.The computer's display capabilities are the primary determinant of the order in which user interfacedesign activities are completed.5.Object-oriented domain analysis is concerned with the identification and specification of reusableclasses within an application domain.6.Test planning can begin as soon as the analysis model is complete.7.The purpose of software reviews is to uncover errors in work products so they can be removed beforemoving on to the next phase of development.8.Once a software engineering work product becomes a baseline it cannot be changed again.9.Tasks that lie on the critical path in a task network may be completed in any order as long as theproject is on schedule.10.The generic process framework — communication, planning, modeling, construction and deployment— is not applicable to WebE.III. Please give brief answers to the following questions: (20 pts.)1.Please list three characteristics that can serve as a guide to evaluate design quality. (6 pts)2.For the statement if ((A>B)||(C==D)), what is the minimum number of test cases required to testevery condition at least once? Please briefly verify your answer. (6 pts)3.Please describe the three partitioning strategies that can be used when performing class-level testingfor object-oriented systems. (6 pts.)4.Please describe the contents of the WebApp functional, and interaction models. (2 pts.)IV. Order-Processing System (50 pts.)Software scope:A company is establishing a new catalog sales division (分类推销部) to sell casual apparel (便装) and outdoor merchandise (户外活动商品). The casual apparel catalog includes shirts (bowling shirts, golf shirts, racing shirts, college shirts, etc.), wears (ladies wear, active wear, outer wear, etc.), jackets (leather jackets, rain jackets, casual jackets, etc.), and others such as sunglasses, hats, pants, and more. The outdoor merchandise catalog includes goods for hunting, fishing, camping, and more. The catalog will be published on the World Wide Web, and orders can be placed by e-mail, via the web site, or via telephone, or fax. A client/server system will be built to support order processing at the company site. The orders are to be collected daily from all places, and be stored in a database. Everyday at 6:00pm, the orders are classified and sent to the corresponding shipment departments. Shipment can be made if payment is by credit card, and must wait until the check is cashed if payment is by check. If the odered item is out of storage, a notification will be sent to the customer, and the order will be delayed or canceled, depending on the customer’s decision.1.Please draw the data flow diagram for processing an order. (12 pts.)2.Please give the two CRC cards for classes “catalog” and “order”. (8 pts.)3.Please give the use-case for browsing the web-site and place an order with creditcard payment. (10 pts.)4.Please draw the corresponding NSU for the use-case described in step 3. (10 pts.)5.Please draw the overall hierarchical call-and-returen architecture of the system. (10pts.)Answer SheetPart I1. 2. 3. 4. 5.6. 7. 8. 9. 10.Part II1. 2. 3. 4. 5.6. 7. 8. 9. 10.Part III and Part IV。
数据结构期末考试参考答案
2008年数据结构期末考试参考答案一、填空题(每空1分,共10分)1、 n-12、 43、 O(logn)4、 35、快速6、 N-17、 CBA8、关键字的值9、广度优先 10、 n-1二、选择题(每小题1分,共10分)1~5 C D A C C 6~10 B A C A D三、应用题(每小题10分,共50分)1.二叉树:5分前序遍历结果为:EBAFDCGIHJ (5分)2.(10分)3:(1)广度优先搜索生成树为:(5分)(2)拓扑排序序列(有三个,答出一个给满分):(5分)1:A,B,C,D,F,E2:A,B,D,C,F,E3:A,D,B,C,F,E4:(1)快速排序:(5分)第一趟,(10)12 (30,28,16,18)第二趟:(10)12 (18,28,16)30第三趟:(10)12 16 (18,28)30(2)冒泡排序:,(5分)第一趟:12,16,28,10,18,30第二趟:12,16,10,18,28第三趟:12,10,16,18第四趟:10,12,16第五趟:10,125:(1) 哈希表为:(5分)四、算法设计题(30分)1、(5分)第一层FOR循环判断n+1次,往下执行n次,第二层FOR执行次数为(n+(n-1)+(n-2)+…+1),第三层循环受第一层循环和第二层循环的控制,其执行次数如下表:i = 1 2 3 … nj=n n n n … nj=n-1 n-1 n-1 n-1 ……………j=3 3 3j=2 2 2j=1 1(1+2+…+n)+(2+3+…+n)+…+n=n*n(n+1)/2-n(n*n-1)/6 算法的阶为O(n3)2、(5分)(1): i = 0;(2): i < n (或i <= n-1)(3): return i(4): i++(5): return –13、(10分)堆栈的数据结构(顺序表实现)template class Stack {private:// Maximum size of stackint size;// Index for top elementint top;// Array holding stack elementsElem *listArray;}bool push(const Elem& item) {if (top == size) return false; else{ listArray[top++] = item;return true;}}bool pop(Elem& it) {if (top == 0) return false; else{ it = listArray[--top];return true;}}队列的数据结构(链表实现)template class Queue { private:Link *front;Link *rear;int size;}bool enqueue(const Elem& it) {if (rear==NULL)front=rear=new Link(it, NULL); else {rear->next = new Link(it, NULL); rear = rear->next;}size++;return true;}bool dequeue(Elem& it) {if (size==0) return false;it=front->element;Link *ltemp=front;front = front->next;delete ltemp;if (front == NULL) rear = NULL;size--;return true;}void reverse(Queue& Q, Stack& S) {ELEM X;while (!Q.isEmpty()) {X = Q.dequeue();S.push(X);}while (!S.isEmpty()) {X = S.pop();Q.enqueue(X);}}4、(10分)int leafnodenumber (bitree *root){if (root = = NULL) return 0;if ((root->lchild = = NULL)&&( root-> rchild = = NULL)) return 1;return (leafnodenumber (root->lchild) + leafnodenumber(root->rchild));}。
浙大计算机机试历年真题
浙江大学历年机试真题2011 A+B forMatricesGrading MedianGraduateAdmission2010 A+B ZOJ问题奥运排序问题最短路径问题二叉搜索树2009 xxx定律ZOJ 继续xxx定律寻找大富翁找出直系亲属2008 又一版A+B欧拉回路继续畅通工程魔咒词典毕业bg2007 最小长方形统计字符游船出租EXCEL排序畅通工程最大报销额2006 还是A+B 火星A+B 还是畅通工程统计同成绩学生人数简单计算器2005 A + B 最大连续子序列畅通工程开门人和关门人排名2011年题目1001:A+B for Matrices时间限制:1 秒内存限制:32 兆特殊判题:否提交:2490 解决:1130题目描述:This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns.输入:The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matr ices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B.The input is terminated by a zero M and that case must NOT be processed.输出:For each test case you should output in one line the total number of zero rows and columns of A+B.样例输入:2 21 11 1-1 -110 92 31 2 34 5 6-1 -2 -3-4 -5 -6样例输出:15题目1002:Grading题目描述:Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible. One way is to assign each exam problem to 3 independent experts. If they do not agree to each other, a judge is invited to make the final decision. Now you are asked to write a program to help this process.For each problem, there is a full-mark P and a tolerance T(<P) given. The grading rules are: • A problem will first be assigned to 2 experts, to obtain G1 and G2. If the differenc e is within the tolerance, that is, if |G1 - G2| ≤ T, this problem's grade will be the average of G1 and G2.• If the difference exceeds T, the 3rd expert will give G3.• If G3 is within the tolerance with either G1 or G2, but NOT both, then this p roblem's grade will be the average of G3 and the closest grade.• If G3 is within the tolerance with both G1 and G2, then this problem's grade will be the maximum of the three grades.• If G3 is within the tolerance with neither G1 nor G2, a judge will give the final grade GJ.输入:Each input file may contain more than one test case.Each case occupies a line containing six positive integers: P, T, G1, G2, G3, and GJ, as described in the problem. It is guaranteed that all the grades are valid, that is, in the interval [0, P]. 输出:For each test case you should output the final grade of the problem in a line. The answer must be accurate to 1 decimal place.样例输入:20 2 15 13 10 18样例输出:14.0题目1004:Median题目描述:Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the non-decreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.Given two increasing sequences of integers, you are asked to find their median.输入:Each input file may contain more than one test case.Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤1000000) is the size of that sequence. Then N integers follow, separated by a space.It is guaranteed that all the integers are in the range of long int.输出:For each test case you should output the median of the two given sequences in a line.样例输入:4 11 12 13 145 9 10 15 16 17样例输出:13题目1005:Graduate Admission题目描述:It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are: • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.• If there is a tied final grade, the applica nts will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.• Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.• If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.输入:Each input file may contain more than one test case.Each case starts with a line containing three positive integers: N (≤40,000), the total number of applicants; M (≤100), the total number of graduate schools; and K (≤5), the number of choices an applicant may have.In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.输出:For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output anempty line correspondingly.样例输入:11 6 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4样例输出:0 1035 6 72 81 42010题目1003:A+B题目描述:给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
浙江大学2007–2008学年夏季学期C程期末试卷
浙江大学2007–2008学年夏季学期《 C程序设计基础与实验》课程期末考试试卷开课学院:计算机学院,考试形式:闭卷,允许带 / 入场考试时间:2008年6月26日上午10:30-12:30, 所需时间:120分钟任课教师:______________考生姓名: _____学号: ______专业:_______________ 注意:答题内容必须写在答题卷上,写在本试题卷上无效。
一、单选题(每题1分,共10分)1. 假定以下表达式中所有变量均已定义为int类型并已赋值,请问其中哪个表达式没有语法错误?A. x = 3.14%2;B. y = 2a+b;C. m = a<b<c;D. n = (-x)++;2. 表达式 'A'+'B' 的类型为:A. charB. intC. doubleD. void3. 执行以下这段程序后,unsigned char a=0;int b=1;do {b++;a--;} while(a!=0);变量b的值等于多少?A. 0B. 1C. 128D. 2574. 如果一个函数的返回值类型为void,则以下哪个说法是正确的?A. 该函数中不可以用return语句B. 该函数中可以用return语句,但必须是最后一个语句C. 该函数中可以用return语句,但return后面不能跟任何表达式D. 该函数可以返回一个任意类型的值,也可以没有返回值5. 执行以下程序后,char a[]="ABC\\XYZ\007\xFF";int n;n = sizeof(a);变量n的值等于多少?A. 10B. 14C. 9D. 176. 用scanf()输入一个double类型的变量的值,则输入格式要用A. "%f"B. "%lf"C. "%f"或"%lf"D. "%ld"7. 假定有以下变量定义语句,float * p,q;请问哪个说法是正确的?A. p和q的类型均为(float *)B. p的类型为(float *),q的类型为floatC. p的类型为float,q的类型为(float *)D. 此变量定义语句有语法错误8. 执行以下程序后,char a = '0';printf("%X", a);将输出什么结果?A. 30B. 0x30C. 0X30D. 09. 假定有如下定义,struct st {char name[10];int score;} a[3], *p=a;请问哪个用法是正确的?A. p->name="Tom";B. *[0]='B';C. (*p)->name[0]='C';D. *(*p).name='D';10. 执行以下语句后,int n = strcmp("ABC", "AB");则以下关于n值的描述哪一个是正确的?A. n=0B. n=1C. n>1D. n<0二、填空题(每题2分,共20分)1. 执行以下代码后,将输出______________。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
for(j=i; j>0; j/=2)
printf(“%d\n”, j);
a. O(n)
b. O(n*n)
c. O(nlogn)
d. O(n*i)
(2) Suppose that the time complexities of two programs are given by T1(N)=O(f(N))
MaxElement = c
;
LastElement = H->Elements[ H->Size-- ];
for( i = 1; i * 2 <= H->Size; i = Child )
{ Child = i * 2;
if( d
)
Child++;
if( LastElement < H->Elements[ Child ] )
minimum
spanning tree(s) of G. (2 points)
a. only one
b. one or more
c. more than one d. zero or more
(9) To find the shortest path between a pair of given vertices,
void Shellsort( ElementType A[ ], int N ) {
int i, j, Increment; ElementType Tmp;
for ( Increment = N / 2; Increment > 0; Increment /= 2 )
for ( i = Increment; i < N; i++ ) {
d
;
}
return MaxSum;
}
III. Please write or draw your answers for the following problems on the answer sheet. (41 points)
(1) In the given graph, start from vertex A,
from S will be inserted into Q immediately. If the output of Q is b, d, c,
f, e, a, the minimum capacity of S must be
. (2 points)
a. 6
b. 5
c. 4
d. 3
(4) Suppose that the size of a hash table is 11, and the hash function is
(1) The function is to delete the maximum element in a max heap. (12 points)
ElementType DeleteMax( PriorityQueue H ) {
int i, Child; ElementType MaxElement, LastElement;
(4) Given a list of N elements and an integer k. Please describe two different algorithms for finding the kth largest element and give the time complexities. (8 points)
(3) Given an empty stack S and an empty queue Q. A list of characters are pushed
into S in the order of a, b, c, d, e, f and every character that is popped
int MaxSubsequenceSum(int A[], int N) {
int ThisSum, MaxSum, j; ThisSum=MaxSum=0;
for(j=0; j<N; j++) {
ThisSum = c
;
if (ThisSum >MaxSum)
MaxSum= ThisSum;
else if (ThisSum <0)
浙江大学 2007–2008 学年秋季学期
《数据结构基础》课程期末考试试卷
开课学院: 软件学院、计算机、竺可桢学院 ,考试形式:闭卷,允许带_ 无 入场
考试时间:_2007_年_11_月_17 日, 所需时间: 120 分钟
考生姓名:
___学号:
专业:
____教师:
题序
一
二
三
四
总分
得分
评卷人
Answer Sheet
operations, the last element of the heap is
. (2 points)
a. 10
b. 11
c. 8
d. 5
(7) Let T be a tree created by union-by-size with N nodes, then the height of
with key=49 will be
. (2 points)
a. 4
b. 7
c. 8
d. 10
(5) For a binary tree, given the postorder traversal sequence FDEBGCA and the
inorder traversal sequence FDBEACG, the corresponding preorder traversal
IV. If each vertex in an undirected weighted graph has a number of balloons assigned. Explain how to modify Dijkstra's algorithm so that if there is more than one minimum path from v to w, a path with the maximum number of balloons is chosen. (15 points) Note : T[ V ].balloon contains the number of balloons at vertex V.
I. Please select the answer for the following problems. (20 points)
(1) The time complexity of the following piece of code is
(2 points)
for(i=0; i<n; i++)
Tmp = A[ i ]; for ( j = i; c
if(d
; j - = Increment ) )
A[ j ] = A[ j - Increment ];
else break;
A[ j ] = Tmp;
}
}
(3) The function is to find maximum sum value of the subsequence in A[0], A[1], A[2], … A[N-1]. (6 points)
(a)the resulting binary search tree; (10 points) and (b)the resulting binary search tree after 72 is deleted. (3 points)
(3) The array representation of the disjoint sets is given by { 2, –4, 2, 2, -3, 5, 6, 9, -2 }. Please list the resulting array elements after invoking Union(7, 9) with union-by-size. Keep in mind that the elements are numbered from 1 to 9. (5 points)
method
can be used. (2 points)
a. Kruskal
b. Dijkstra
c. Hashing
d. Critical Path
(10) Among the following sorting algorithms,
has the average run time
O(NlogN) with O(N) extra spaces. (2 points)
4
Please list:
D
(a) the depth-first search sequence;
2
(b) the breath-first search sequence; and
(c) the minimum spanning tree.
A 5
7
B
C
64
11 5
7
E4
F
31
6
6 5
H
4
I
J
4 8G
H(key)=key%11. The following 4 elements have been inserted into the table
as Addr(14)=3, Addr(38)=5, Addr(61)=6, Addr(86)=9. When open addressing
with quadratic probing is used to solve collisions, the address of the element