《数据结构英文试卷a及答案.doc》由会员分享,可在线阅读,更多相关《数据结构英文试卷a及答案.doc(11页珍藏版)》请在三一办公上搜索。
1、北 京 交 通 大 学 软 件 学 院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
2、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 adjace
3、ncy 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. B. /2 C. e /2 D. 5. 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 wi
4、th 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
5、 ) 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
6、 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.
7、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 sim
8、ilar 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 tu
9、rn. 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,
10、 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
11、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 th
12、e 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
13、 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 sele
14、ction 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
15、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 d
16、egree 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 (2poi
17、nts)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
18、)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 siz
19、eof(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
20、 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, w
21、rite 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; typed
22、ef 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; fo
23、r(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); int ShortestPath(int u,int v)/* 求u和v之间经过的分支数最少的路径*/ int k,pren,spathn,count=0,found=0; EdgeNode * p; if(u=v) printf(errorn); return 0; Q=(CirQueue*
24、)malloc(sizeof(CirQueue); Q-front=Q-rear=0; for(k=0;kdataQ-rear+=u; while(!found & Q-front!=Q-rear) k=Q-dataQ-front+; p=Gk.firstedge;while(p & !found) if(visitedp-adjvex=0) prep-adjvex=k; if(p-adjvex=v) found=1; break; visitedp-adjvex=1; Q-dataQ-rear+=p-adjvex; p=p-next; if(found) printf(found: ); s
25、pathcount+=v; k=prev;while(k!=u) spathcount+=k; k=prek;spathcount=u; for(k=count;k=0;k-) printf(%d , spathk);printf(n); return 1; elseprintf(There is no pathn); return 0;main() int i,j; createALGraph(); print(); for(i=0;ifch ); (2分)h2 = TreeDepth( T-nsib); (2分)if(h1+1 h2) return(h1+1)else return(h2); (2分)