已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
北 京 交 通 大 学 软 件 学 院20122013学年第一学期期末考试试题 data structure and algorithm design(a)class: _student number: _name: _ teacher_no.iiiiiiivvvitotalmarki. single-choice(20 points)1. the height of a binary tree that contains 1023 elements is at most ( 1 ) and at least ( 2 ).a 1022 b1023 c 1024 d9 e10 f112. if the sequence of pushing elements into a stack is a,b,c, which output sequence is impossible?( )aabc bbca ccba dcab 3.how many minimum-cost spanning trees are there for an undirected connected graph with n vertices and e edges? ( ) a. must be only one b. n-1 c. n-e d. not sure4. when using the adjacency matrix a to represent a undirected graph with n nodes and e edges, the degree of the node vi can be computed by formula ( ).a. i=1nai,j b. j=1nai,j/2 c. e /2 d. i=1nai,j+j=1nai,j5. in the worst case, time complexity of quicksort will be degraded to ( ).ao(n) bo(n2) co(nlogn)6.in order to find a specific key in an ordered list with 100 keys using binary search algorithm, the maximum times of comparisons is ( ).a. 25 b.10 c. 1 d.77. consider the following pseudo-code, which indicates part of a standard binary tree algorithm. print( node ) print data; if( there is a left child ) print( left child ); if( there is a right child ) print( right child ); which of the following is the standard name for this algorithm? ( )a. inorder traversal b. preorder traversalc. postorder traversal d. binary search8.which is not the property of a b-tree of order m? ( )a. the root node has m subtree at most b. all leaf nodes are at the same level.c. the keys in every node are ordered. d. all leaf nodes are connected by links. 9. suppose that we have 1000 distinct integers, which are in the range from 0 to 50. if using radix sort according to the least significant digit first, ( ) buckets are needed to constructed.a. 10 b. 50 c. 51 d. 1000answer table for question i (write your answers of question i here)1(1)1(2)23456789be d d a b d b daii. fill in the blank (2points * 5)answer table for ii (please write your answers of ii here)12234preorder112,3,5i*n+j5,4,3,2,11. the strategy of depth-first searching algorithm for a graph is similar to that of_ _ traversal algorithm for a normal tree. 2. here is a hash table, whose size is 18, hashing function is h1(key)=key%17 (% here is the modulus operator), and which uses linear probing strategy to cope with the collisions and inserts 26, 25, 72, 38, 8, 18, 59 into the hash table in turn. the address of 59 is _ _ _.3. given a key sequence 2,5,3, please write its ascending ordered sequence after being sorted using heap sort. (note 5=, just 5 is before in original sequence) . please distinguish 5 and .4. if a 2-dimensions matrix amn is stored in an 1-d array with row-major mapping, then the address of element aij relative to a00 is _ _5. if the in-order and pre-order series of the nodes in a binary tree are “1,2,3,4,5” and “1,2,3,4,5” respectively, the postorder sequence should be _.iii. (40 points)1. (8 points) suppose there is a string abcadececdcdeeeded that comprises the characters a, b, c, d and e. we may encode the symbols using variable-length codes in order to make the length of string the shortest. please draw the huffman tree used to encode the characters, calculate the weighted path length for the huffman tree and write the code for each character.(1) draw the huffman tree (3 points)a:2, b:1, c:4, d:5 , e: 6 (3 points)(2) calculate the weighted path length for the huffman tree (2 points) wpl(t)= 62+52+23+13+42 =39 (3) write the code for each character. (3 points) 错一个扣一分,扣光为止abcde1001011101002. (8 points) please respectively give two unsorted lists whose length are 4 to illustrate that quick sort and selection sort are unstable.(1) an example list for quick sort and the sorting procedure using quick sort. (4 points)(4, 2, , 3)- (2 points)sorting procedure the first pass: 3,2, ,4 -(1point)the second pass: ,2,3,4 -(1point)(2) an example list for selection sort and the sorting procedure using selection sort. (4 points)(2,3,1)- (1 points)sorting procedure the first pass: 1, , 3 , 2 -(1point)the second pass: 1, , 3 , 2 -(1point)the third pass: 1, , 2, 3 -(1point)3. (8 points) given the key sequence (331, 166, 367, 236, 268, 137, 337, 138), please give the procedure (distributing and collecting) of sorting using radix sort method. not necessary to write queue front and rear pointer if queue is null. (1) the first pass (3 points) (2) the second pass (3 points)(3) the third pass (2 points)4.(6 points)there are n1 nodes of degree 1,n2 nodes of degree 2,nm nodes of degree m in a tree of degree m,how many leaf nodes there are in the tree? please give formula and prove your conclusion.answer:because every node except root has one branch linked, so total nodes are equal to total branches plus one, there are n branches in node of degree n (2points)formula such as (2points) (2points)5. (10 points) show the result of inserting 63, 37, 48, 100, 54, 64, 27, 108, 99, 42 into (a) an empty binary search tree(2 points) (b) an initially empty avl tree(4 points)(c) an initially empty b-tree of order 3(4 points)answer:(1) binary search tree(2 points)63 10037108486427994254 (2)avl (4 points) (3) b-tree (4points)iv. (10 points) please fill in the blanks in the program which reverses a singly linked list. for example, 1,2,3,4,5,6,7,8,9,10 will become 10,9,8,7,6,5,4,3,2,1 after being reversed.#define list_init_size 100 #define n 10 #define len sizeof(struct node)typedef struct node int num; struct node *next; lnode,*link; link llist; static int a=1,2,3,4,5,6,7,8,9,10;void creat(link *list) /create a singly linked list for key sequence stored in array a int i=0; lnode *p,*q; q=(struct node*)malloc(len); q-num=ai; *list=q; while (inext=0; void reverselist(link *h) / reverse the singly linked list lnode *p,*q, *r; p=*h; r=0; while (p) q=p; (3) ; (4) ; r = q; (5) ; main() lnode *l; creat(&l); reverselist(&l); answer:(1) _ p-num=ai;_(2) _ q-next=p;_(3) _ p=p-next;_(4) _ q-next =r;_ (5) _ _*h=q;_v.(10 points)please read the following code, write the functions of programs and write output of the program.#include#include malloc.h#define n 6static char chn=a,b,c,d,e,f; static int ann=0,1,1,0,0,0, 1,0,0,1,1,0, 1,0,0,1,0,1, 0,1,1,0,0,1, 0,1,0,0,0,1, 0,0,1,1,1,0; typedef struct node /*邻接表中的边结点*/ int adjvex; struct node *next; edgenode; typedef struct vnode /*邻接表中的顶点结点*/ char vertex; edgenode *firstedge; vertexnoden; typedef struct int front,rear; int datan; cirqueue; cirqueue *q; int pathn,sum=0; int visitedn; vertexnode g;void createalgraph() /*根据邻接矩阵,建无向网的邻接表表示*/int i,j; edgenode *s; for(i=0; in; i+) gi.vertex=chi; gi.firstedge=0; for(i=0; in; i+) for(j=0; jadjvex=j; s-next=gi.firstedge; gi.firstedge=s; void print() int i; edgenode *s; for (i=0; iadjvex.vertex); s=s-next; printf(n);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年宜昌市事业单位集中公开招聘工作人员392人笔试备考试题及答案解析
- 2026重庆德润环境有限公司招聘2人笔试参考题库及答案解析
- 2026四川省现代种业发展集团种芯农业有限公司招聘财务人员(会计岗)1人笔试模拟试题及答案解析
- 2026湖南湘潭湘乡市医疗卫生机构公开招聘(人才引进)事业单位专业技术人员43人考试模拟试题及答案解析
- 2026年度上半年黑龙江工业学院招聘人事代理人员32人笔试模拟试题及答案解析
- 四川铁道职业学院2026年上半年公开招聘工作人员(9人)笔试模拟试题及答案解析
- 2026年福建宁德仲裁委员会招聘仲裁员200人笔试备考题库及答案解析
- 2026年双金属管件行业分析报告及未来发展趋势报告
- 2026陕西汉中市洋县实验学校教师招聘笔试模拟试题及答案解析
- 2026年白银有色集团股份有限公司应届高校毕业生技能操作岗校园招聘522人考试备考试题及答案解析
- 2024中华护理学会团体标准-注射相关感染预防与控制
- 东方航空合同管理制度
- 危机公关与舆情应对
- 腹针完整版本
- 非职权影响力培训
- 部编人教版小学四年级下册道德与法治一课一练(含答案全一册)
- 医疗器械效期管理制度
- 小学生主题班会 防震减灾安全教育课件
- 用电信息采集系统
- 关节松动技术-课件
- 标准化推动企业质量管理与创新发展
评论
0/150
提交评论