2009级数据结构试卷A及答案 - 副本
2009年《数据结构》试卷A答案

西华大学课程考试参考答案(A卷)课程代码: 8401801 试卷总分: 100 分一、单项选择题参考答案及评分标准:(本大题共20个小题,每小题2分,共40分)评分标准:选对一题得2分,不选或选错得0分。
1-5:CBACC 6-10:CCBDB 11-15:ABCCD 16-20:CADDC二、算法理解题参考答案及评分标准:(本大题共3个小题,第1、2小题各7分,第3小题6分,共20分)评分标准:请根据各解答步骤酌情给分。
1. 解:构造过程各图(略),最后结果为:2. 解:设权w=(5,29,7,8,14,23,3,11),可构造一棵赫夫曼树如下图所示。
所得赫夫曼编码为:A: 0110B: 10C: 1110D: 1111E: 110F: 00G: 0111H: 0103. 解:(1)希尔排序第一趟(增量d=5)排序后 7、12、36、23、12、51、60、55、72、49第二趟(增量d=3)排序后 7、12、36、23、12、51、49、55、72、60第三趟(增量d=1)排序后 7、12、12、23、36、49、51、55、60、72(2)归并排序第一趟排序后 12、51、23、55、7、49、36、60、12、72第一趟排序后 12、23、51、55、7、36、49、60、12、72第三趟排序后 7、12、23、36、49、51、55、60、12、72第四趟排序后 7、12、12、23、36、49、51、55、60、72三、算法设计题参考答案及评分标准:(本大题共4个小题,每小题10分,共40分)评分标准:请根据编程情况酌情给分。
1. 参考答案示例:void DelInsert(LinkList &L){∥本算法将带头结点的非空单链表L中数据域值最小的那个结点移到链表的最前面。
p=L->next;∥p是链表的工作指针pre=L;∥pre指向链表中数据域最小值结点的前驱。
q=p;∥q指向数据域最小值结点,初始假定是首元结点while (p->next!=NULL){ if(p->next->data<q->data){ pre=p;q=p->next;} ∥找到新的最小值结点 p=p->next;}if (q!=L->next){ pre->next=q->next;∥将最小值结点从链表上摘下q->next= L->next;∥将q结点插到链表最前面L->next=q;}}//DelInsert2. 参考答案示例:void Count(BiTree T,int &n0,int &n){//统计二叉树T上叶结点数n0和非叶结点数n。
2009年9月答案解析

2009年9月二级VF笔试真卷参考答案一、选择题(1)C)【解析】根据数据结构中各数据元素之间的前后件关系的复杂程度,一般将数据结构分为两大类:线性结构和非线性结构。
循环队列、带链队列和带链栈都是线性结构,而二叉树是非线性结构。
(2)B)【解析】栈按照“先进后出”(FILO)或“后进先出”(LIFO)组织数据;队列是“先进先出”(FIFO)或“后进后出”(LILO)的线性表。
(3)D)【解析】所谓循环队列,就是将队列存储空间的最后一个位置绕到第一个位置,形成逻辑上的环状空间,供队列循环使用。
在循环队列中,用队尾指针rear指向队列中的队尾元素,用排头指针front指向排头元素的前一个位置。
循环队列的主要操作是:入队运算和退队运算。
每进行一次入队运算,队尾指针就进一。
每进行一次退队运算,排头指针就进一。
当rear或front等于队列的长度加1时,就把rear 或front值置为1。
所以在循环队列中,队头指针可以大于队尾指针,也可以小于队尾指针。
(4)A)【解析】算法的空间复杂度是指执行这个算法所需要的内存空间。
这个内存空间包括算法程序所占的空间,输入的初始数据所占的存储空间以及算法执行过程中所需要的额外空间。
(5)B)【解析】耦合性与内聚性是模块独立性的两个定性标准。
一般一个较优秀的软件设计,应尽量做到高内聚,低耦合,即减弱模块之间的耦合性和提高模块内的内聚性,有利于提高模块的独立性。
(6)A)【解析】结构化设计方法的主要原则可以概括为自顶向下、逐步求精、模块化限制使用goto语句。
(7)C)【解析】N-S图把整个程序写在一个大框图内,这个大框图是由若干个小的基本框图构成的流程图。
E-R图即实体-联系图(Entity Relationship Diagram),提供了表示实体型、属性和联系的方法,用来描述现实世界的概念模型。
PAD是问题分析图,用二维树形结构的图表示程序的控制流,将这种图转换为程序代码比较容易。
数据结构真题2009年下半年

数据结构真题2009年下半年(总分:124.98,做题时间:90分钟)一、{{B}}单项选择题{{/B}}(总题数:15,分数:30.00)1.按值可否分解,数据类型通常可分为两类,它们是 ( )(分数:2.00)A.静态类型和动态类型B.原子类型和表类型C.原子类型和结构类型√D.数组类型和指针类型解析:[解析] 按“值”是否可分解,可将数据类型划分为两类:原子类型,其值不可分解;结构类型,其值可分解为若干个成分。
2.对于三个函数f(n)=2008n3+8n2+96000,g(n)=8n3+8n+2008和h(n)=8888nlogn+3n2,下列陈述中不成立的是 ( )(分数:2.00)A.f(是O(g()B.g(是O(f()C.h(是O(nlog √D.h(是O(n2)解析:[解析] 当n充分大时,由题意可得:f(n)与n3是同阶的,g(n)与n3是同阶的,h(n)与n2是同阶的。
所以f(n)=O(g(n)),g(n)=O(f(n)),h(n)=O(n2)。
3.指针p、q和r依次指向某循环链表中三个相邻的结点,交换结点*q和结点*r在表中次序的程序段是( ) (分数:2.00)A.p—>next=r; q—>next=r—>next; r—>next=q; √B.p—>next=r; r—>next=q; q—>next=r—>next;C.r—>next=q; q—>next=r—>next; p—>next=r;D.r—>next=q; p—>next=r; q—>next=r—>next;解析:4.若进栈次序为a,b,e,且进栈和出栈可以穿插进行,则可能出现的含3个元素的出栈序列个数是 ( ) (分数:2.00)A.3B.5 √C.6D.7解析:5.假设以数组A[n]存放循环队列的元素,其头指针front指向队头元素的前一个位置、尾指针rear指向队尾元素所在的存储位置,则在少用一个元素空间的前提下,队列满的判定条件为 ( )(分数:2.00)A.rear==frontB.(front+1)%n==rearC.rear+1==frontD.(rear+1)%n==front √解析:[解析] 在循环队列中,在少用一个元素空间的前提下,可约定入队前,测试尾指针在循环意义下加1后是否等于头指针,若相等则认为队满。
数据结构试题及答案(1)A

数据结构试卷一、填空殖(每空1分共20分)1.数据的物理结构主要包括___顺序存储结构__________和_链式_____________两种情况。
2.设一棵完全二叉树中有500个结点,则该二叉树的深度为_______9___;若用二叉链表作为该完全二叉树的存储结构,则共有______501_____个空指针域.3.设输入序列为1、2、3,则经过栈的作用后可以得到_____6______种不同的输出序列。
4.设有向图G用邻接矩阵A[n][n]作为存储结构,则该邻接矩阵中第i行上所有元素之和等于顶点i的___出度_____,第i列上所有元素之和等于顶点i的____入度____。
5.设哈夫曼树中共有n个结点,则该哈夫曼树中有___0_____个度数为1的结点。
6.设有向图G中有n个顶点e条有向边,所有的顶点入度数之和为d,则e和d的关系为____e=d_____。
7.____中序______遍历二叉排序树中的结点可以得到一个递增的关键字序列(填先序、中序或后序).8.设查找表中有100个元素,如果用二分法查找方法查找数据元素X,则最多需要比较_____7___次就可以断定数据元素X是否在查找表中。
9.不论是顺序存储结构的栈还是链式存储结构的栈,其入栈和出栈操作的时间复杂度均为______1______。
10.设有n个结点的完全二叉树,如果按照从自上到下、从左到右从1开始顺序编号,则第i个结点的双亲结点编号为___i/2_________,右孩子结点的编号为____2i+1_______。
11.设一组初始记录关键字为(72,73,71,23,94,16,5),则以记录关键字72为基准的一趟快速排序结果为_____5 16 71 23 72 94 73______。
12.设有向图G中有向边的集合E={〈1,2〉,<2,3>,〈1,4〉,〈4,2>,〈4,3〉},则该图的一种拓扑序列为___1 4 2 3___。
数据结构试卷试题及答案

数据结构试卷试题及答案一、选择题(每题5分,共40分)1. 数据结构是研究数据元素的()A. 存储结构B. 处理方法C. 逻辑结构D. 所有以上内容答案:D2. 在数据结构中,通常采用()方式来表示数据元素之间的逻辑关系。
A. 顺序存储结构B. 链式存储结构C. 索引存储结构D. 散列存储结构答案:B3. 下面哪一个不是栈的基本操作?()A. 入栈B. 出栈C. 判断栈空D. 获取栈顶元素答案:D4. 下面哪一个不是队列的基本操作?()A. 入队B. 出队C. 判断队列空D. 获取队头元素答案:D5. 下面哪一个不是线性表的特点?()A. 有且只有一个根节点B. 每个节点最多有一个前驱和一个后继C. 数据元素类型相同D. 数据元素类型可以不同答案:D6. 在下列哪种情况中,使用链式存储结构比顺序存储结构更合适?()A. 数据元素经常插入和删除B. 数据元素大小不固定C. 数据元素个数不确定D. 所有以上情况答案:D7. 下面哪一个不是树的遍历方式?()A. 前序遍历B. 中序遍历C. 后序遍历D. 翻转遍历答案:D8. 在下列哪种情况中,使用散列存储结构比其他存储结构更合适?()A. 数据元素个数较少B. 数据元素查找频繁C. 数据元素插入和删除频繁D. 数据元素大小不固定答案:B二、填空题(每题5分,共30分)9. 栈是一种特殊的线性表,它的插入和删除操作都限定在表的一端进行,这一端称为______。
答案:栈顶10. 队列是一种特殊的线性表,它的插入操作在表的一端进行,这一端称为______,而删除操作在另一端进行,这一端称为______。
答案:队尾、队头11. 二叉树中的节点包括______和______。
答案:根节点、子节点12. 在图的存储结构中,邻接矩阵表示法用______个一维数组来表示图中各个顶点之间的关系。
答案:两个13. 散列存储结构中,关键码到存储地址的映射方法称为______。
数据结构样卷答案09级

③ 改正:函数体最后增加以下一句: element[len] = '\0'; (3) 深拷贝创建二叉树时,没有为各结点建立指向父母结点的链。改正如下: ① 当 TriNode 构造函数不指定 parent 时 template <class T> TriNode<T>* TriBinaryTree<T>::copy(TriNode<T> *p) { TriNode<T> *q=NULL; if (p!=NULL) { q = new TriNode<T>(p->data); q->left = copy(p->left); if (q->left!=NULL) q->left->parent = q; q->right = copy(p->right); if (q->right!=NULL)
//一次匹配
} if (q!=NULL) { front=start; start=start->next; } else { q=list.head->next;
南京工程学院
试题评分标准及参考答案(样)
2010 / 2011 学年第 2 学期 课程所属部门: 计算机工程学院 使用班级:计算机专业 2009 级各班 课程名称: 数据结构 制作人:叶核亚、黄纬 2011 年 5 月 24 日 共7页 第 1 页
一.
(2) (3) (4) (5) (6) (7)
填空题(26 分,每空 2 分)
pk 与 p j 比较
0 a -1
1 b 0 ≠
2 c 0 ≠ 0
3 a 0 = -1
4 a 1 = 1
2009年10月全国自考数据结构真题及答案

更多优质自考资料尽在百度贴吧自考乐园俱乐部(/club/5346389)欢迎❤加入...欢迎❤交流...止不住的惊喜等着你.........2009年10月全国自考数据结构真题一、单项选择题(本大题共15小题,每小题2分,共30分)在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.按值可否分解,数据类型通常可分为两类,它们是()A.静态类型和动态类型B.原子类型和表类型C.原子类型和结构类型D.数组类型和指针类型答案:C2.A. AB. BC. CD. D答案:C3.指针p、q和r依次指向某循环链表中三个相邻的结点,交换结点*q和结点*r在表中次序的程序段是()A.p->next=r;q->next=r->next;r->next=q;B.p->next=r;r->next=q;q->next=r->next;C.r->next=q;q->next=r->next;p->next=r;D.r->next=q;p->next=r;q->next=r->next;答案:A4.若进栈次序为a,b,c,且进栈和出栈可以穿插进行,则可能出现的含3个元素的出栈序列个数是()A. 3B. 5C. 6D.7答案:B5.假设以数组A[n]存放循环队列的元素,其头指针front指向队头元素的前一个位置、尾指针rear指向队尾元素所在的存储位置,则在少用一个元素空间的前提下,队列满的判定条件为()A.rear==frontB.(front+1)%n==rearC.rear+1==frontD.(rear+1)%n==front答案:D6.串的操作函数str定义为:A. 3B. 4C. 5D. 6答案:C7.二维数组A[10][6]采用行优先的存储方法,若每个元素占4个存储单元,已知元素A[3][4]的存储地址为1000,则元素A[4][3]的存储地址为()A.1020B.1024C.1036D.1240答案:A8.对广义表L= (a,())执行操作tail(L)的结果是()A.()B.(())C. aD.(a)答案:B9.已知二叉树的中序序列和后序序列均为ABCDEF,则该二叉树的先序序列为()A.FEDCBAB.ABCDEFC.FDECBAD.FBDCEA答案:A10.已知森林F={T1,T2,T3,T4,T5},各棵树Ti(i=1,2,3,4,5)中所含结点的个数分别为7,3,5,1,2,则与F对应的二叉树的右子树中的结点个数为()A. 2B. 3C.8D.11答案:D11.若非连通无向图G含有21条边,则G的顶点个数至少为()A.7B.8C.21D.22答案:B12.如图所示的有向图的拓扑序列是()A.c,d,b,a,eB.c,a,d,b,eC.c,d,e,a,bD.c,a,b,d,e答案:B13.对关键字序列(6,1,4,3,7,2,8,5)进行快速排序时,以第1个元素为基准的一次划分的结果为()A.(5,1,4,3,6,2,8,7)B.(5,1,4,3,2,6,7,8)C.(5,1,4,3,2,6,8,7)D.(8,7,6,5,4,3,2,1)答案:C14.分块查找方法将表分为多块,并要求()A.块内有序B.块间有序C.各块等长D.链式存储答案:B15.便于进行布尔查询的文件组织方式是()A.顺序文件B.索引文件C.散列文件D.多关键字文件答案:二、填空题(本大题共10小题,每小题2分,若有两个空格,每个空格1分,共20分)请在每个空格中填上正确答案。
数据结构期末试卷_含答案

三、程序填空题(本题共、链式表表示和实现线性表的部分程序如下,请在程序空白处填上适当的语句://线性表的单链表存储结构typedef struct LNode{线 订 装数据结构与算法A卷答案一、选择题:(本题共20小题,每题2分,共40分)1-5:CA、DBCC 6-10:BDDAB 11-15:AABBA 16-20:CCCBC二、分析运算题(本题共5小题,每题6分,共30 分)1、解答:(1)选链式存储结构。
它可以动态申请内存空间,不受表长度(即表中元素个数)的影响,插入、删除的时间复杂性为O(1);(2)选顺序存储结构。
顺序表可以随机存取,时间复杂性为O(1)。
2.CBADECBAEDCBEDACBDAECBDEA每对一个得1分,全对得6分,写错一个倒扣1分。
3.(3分)先序遍历序列:+-A/×BCD/EF (3分)4.(3分)后序遍历序列为:BHECIGFA D (3分)(1)(2分)(2)(2分)(3)(2分)三、程序填空题(本题共10空,每空2分,共20分)(1)p = L(2)p->next(3)p->next=q->next(4)free(q)(5)NULL或=NULL(6)printf(“%c”,BT->data)(7)Inorder(BT->right)(8) Push(S, exp[i]) 或 Push(S,‘(’)(9) GetTop(S)= ='('(10) Pop(S,e)四、算法设计题(本题共1小题,共10分)1、(10分)算法如下:答:void quickpass(sqlist r){int i=0; j=r.length-1; x=r.elem[0];while(i<j){while(i<j && r.elem[j]>x) j=j-1;if(i<j){r.elem[i]=r.elem[j];i=i+1;} while(i<j && r.elem[i]<x) i=i+1;if(i<j){r.elem[j]=r.elem[i];j=j-1;} }r.elem[i]=x;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
(C) Eliminate the recursive calls. (D) Reduce main memory use.(7) Given an array as A[m][n]. Supposed that A[0][0]is located at 644(10) and A[2][2]isstored at 676(10), and every element occupies one space. “(10)” means that thenumber is presented in decimals. Then the element A[4][4](10) is at position:( D )(A) 692 (B) 695 (C) 650 (D) 708(8) If there is 0.5MB working memory, 4KB blocks, yield 128 blocks for workingmemory. By the multi-way merge in external sorting, the average run size and the sorted size in one pass of multi-way merge on average are separately ( C )?(A) 0.5MB, 128 MB (B) 2MB, 512MB(C) 1MB, 128MB (D) 1MB, 256MB(9) Which algorithm is used to generate runs in classic external sorting? ( D )(A) Quick-sort (B) Bubble sort(C ) Insertion sort (D) Replacement selection(10) Assume that we have eight records, with key values A to H, and that they are initially placedin alphabetical order. Now, consider the result of applying the following access pattern: F D F G GF A D F G, if the list is organized by the move-to-front heuristic, then the final list will be( B ).(A)G F D A C H B E(B) G F D A B C E H(C) F D G A E C B H (D) F D G E A B C H2. Fill the blank with correct C++ codes: (16 scores)(1)Given an array storing integers ordered by distinct value, modify the binary search routines toreturn the position of the integer with the greatest value less than K when K itself does not appear in the array. Return ERROR if the least value in the array is greater than K: (10 scores)// Return position of greatest element <= Kint newbinary(int array[], int n, int K) {int l = -1;int r = n; // l and r beyond array boundswhile (l+1 != r) { // Stop when l and r meet___ int i=(l+r)/2_____; // Look at middle of subarrayif (K < array[i]) __ r=i ___; // In left halfif (K == array[i]) __ return i ___; // Found itif (K > array[i]) ___ l=i ___ // In right half}// K is not in array or the greatest value is less than Kif K> array[0] (or l !=-1)return l ; // the integer with the greatest value less than // K when K itself does not appearin the arrayelse return ERROR; // the least value in the array is greater than K}(2) A full 5-ary tree with 100 internal vertices has _501__vertices. (3 scores)(3) The number of different shapes of binary trees with 4 nodes is _14_. (3 scores)3. A certain binary tree has the preorder enumeration as ABECDFGHIJ and the inorder enumeration as EBCDAFHIGJ. Try to draw the binary tree and give the postorder enumeration. (The process of your solution is required!!!) (6 scores)Postorder enumeration : EDCBIHJGFA4. Determine Θ for the following code fragments in the average case. Assume that all variables are of type int.(6 scores) (1) sum=0;for (i=0; i<3; i++) for (j=0; j<n; j++)sum++; solution : Θ___(n)_______(2) sum = 0;for(i=1;i<=n;i++) for(j=1;j<=i;j++)sum++;solution : Θ__(n 2)________(3) sum=0;if (EVEN(n))for (i=0; i<n; i++) sum++; elsesum=sum+n; solution : Θ___(n)_____5. Trace by hand the execution of Quicksort algorithm on the array: int a[] = {49 38 65 97 76 13 27 49*}. The pivot is 49 in the first pass, the following pivots are selected by the same method (at the first position of the input array). (6 scores) initial: [49 38 65 97 76 13 27 49*]pass 1: [27 38 13] 49 [76 65 49* 97]pass 2:[13] 27 [38] 49 [49* 65] 76 [97]pass 3:13 27 38 49 49* [65] 76 97final sorted array:13 27 38 49 49* 65 76 976. Design an algorithm to transfer the score report from 100-point to 5-point, the levelE corresponding score<60, 60~69 being D, 70~79 being C, 80~89 as B,score>=90 as A. The distribution table is as following. Please describe your algorithm using a decision tree and give the total path length.(这是新增加的)(9 scores)Score in 100-point 0-59 60-69 70-79 80-89 90-100 Distribution rate 5% 15% 40% 30% 10%solution:the design logic is to build a Huffman tree (其中C和其兄弟分支交换了位置)Total length: 4 * 5% +10% * 4 + 15 %* 3 + 30% * 2 + 40%= 2.05, the 0-false,1-true as the logic branches.7. Assume a disk drive is configured as follows. The total storage is approximately 675M divided among 15 surfaces. Each surface has 612 tracks; there are 144 sectors/track, 512 byte/sector, and 16 sectors/cluster. The interleaving factor is four. The disk turns at 7200rmp (8.33 ms/r). The track-to-track seek time is 20 ms, and the average seek time is 80 ms. Now how long does it take to read all of the data in a 340 KB file on the disk? Assume that the file’s clusters are spread randomly across the disk. A seek must be performed each time the I/O reader moves to a new track. Show your calculations. (The process of your solution is required!!!) (9 scores) Answer:The first question is how many clusters the file requires?A cluster holds 16*0.5K = 8K. Thus, the file requires 340/8=42.5 clusters=42 complete cluster and 4k(8 sectors)The time to read a cluster is seek time to thecluster+ latency time + (interleaf factor ×rotation time).Average seek time is defined to be 80 ms. Latency time is 0.5 *8.33 ms (60/7200≈8.33ms),and cluster rotation time is 4* (16/144)*8.33.Seek time for the total file read time is42* (80 + 0.5 * 8.33+ 4 * (16/144)*8.33 ) +(80 + 0.5 * 8.33+ 4 * (8 /144)*8.33 )≈3776.44ms8. Using closed hashing, with double hashing to resolve collisions, insert the following keys into a hash table of eleven slots (the slots are numbered 0 through 10). The hash functions to be used are H1 and H2, defined below. You should show the hash table after all eight keys have been inserted. Be sure to indicate how you areusing H1 and H2 to do the hashing. ( The process of your solution is required!!!) H1(k) = 3k mod 11 H2(k) = 7k mod 10+1Keys: 22, 41, 53, 46, 30, 13, 1, 67. (9 scores)Answer:H 1(22)=0, H 1(41)=2, H 1(53)=5, H 1(46)=6, no conflictWhen H 1(30)=2, H 2(30)=1 (2+1*1)%11=3,so 30 enters the 3rd slot; H 1(13)=6, H 2(13)=2 (6+1*2)%11=8, so 13 enters the 8th slot;H 1(1)=3, H 2(1)=8 (3+5*8)%11= 10 so 1 enters 10 (pass by 0, 8, 5, 2 ); H 1(67)=3, H 2(67)=10 (3+2*10)%11= 1 so 67 enters 1(pass by 2)9. You are given a series of records whose keys are integers. The records arrive in the following order: C, S, D, T, A, M, P, I, B, W, N, G , U, R. Show the 2-3 tree that results from inserting these records. (the process of your solution is required!!!) (9 scores)MSBD P U A C GI N R T W 10.1) Use (4 scores)2) Use Kruskal ’s algorithm to find the minimum-cost spanning tree. (3 scores) 3) Show the DFS tree for the following graph, starting at Vertex A. (3 scores)1)C to A: 4 (C,A); CF: 5(C,F); CD: 6(C,A,D); CB: 12(C,A,D,B); CG:11 (C,F,G); CE: 13(C,A,D,B,E)2)3)A---->B---->D--->F---->CGE。