




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、北 京 交 通 大 學(xué) 軟 件 學(xué) 院20122013學(xué)年第一學(xué)期期末考試試題 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. 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
4、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 c
5、hild ); 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
6、 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
7、 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 sear
8、ching 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
9、, 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
10、 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 abca
11、dececdcdeeeded 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 c
12、ode 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)= 6´2+5´2+2´3+1´3+4´2 =39 (3) write the code for each character. (3 points) 錯一個扣一分,扣光為止abcde10010111010
13、02. (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 -(1poi
14、nt)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 th
15、e 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
16、 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 b
17、ranches 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
18、-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
19、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=(s
20、truct node*)malloc(len); q->num=ai; *list=q; while (i<n-1) p=(struct node*)malloc(len); i=i+1; (1) ; (2) ; q=p; p->next=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); reverseli
21、st(&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<stdio.h>#include "malloc.h"#define n 6static char ch
22、n='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 /*鄰接表中的邊結(jié)點*/ int adjvex; struct node *next; edgenode; typedef struct vnode /*鄰接表中的頂點結(jié)點*/ char vertex; edgenode *f
23、irstedge; vertexnoden; typedef struct int front,rear; int datan; cirqueue; cirqueue *q; int pathn,sum=0; int visitedn; vertexnode g;void createalgraph() /*根據(jù)鄰接矩陣,建無向網(wǎng)的鄰接表表示*/int i,j; edgenode *s; for(i=0; i<n; i+) gi.vertex=chi; gi.firstedge=0; for(i=0; i<n; i+) for(j=0; j<n; j+) if (aij=1)
24、 s=(edgenode*)malloc(sizeof(edgenode); s->adjvex=j; s->next=gi.firstedge; gi.firstedge=s; void print() int i; edgenode *s; for (i=0; i<n; i+) s=gi.firstedge; printf(" %c : ",gi.vertex); while(s) printf(" %c",gs->adjvex.vertex); s=s->next; printf("n"); int
25、 shortestpath(int u,int v)/* 求u和v之間經(jīng)過的分支數(shù)最少的路徑*/ int k,pren,spathn,count=0,found=0; edgenode * p; if(u=v) printf("errorn"); return 0; q=(cirqueue*)malloc(sizeof(cirqueue); q->front=q->rear=0; for(k=0;k<n;k+) visitedk=0; prek=-1; visitedu=1; q->dataq->rear+=u; while(!found &a
26、mp;& 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: "); spathcount+=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
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)藥買賣合同范本
- 《有趣的條紋》中班綜合教案
- 倉庫商品售賣合同范本
- 印章模板采購合同范本
- 《因數(shù)與倍數(shù)》教學(xué)反思
- 供貨瓷磚合同范本
- 雙人合資合同范本
- 臺式計算機供貨合同范例
- 個人汽車銷售合同范本
- 單位職工解除勞動合同范本
- 新公務(wù)員法培訓(xùn)講稿
- 用人部門面試官培訓(xùn)
- 荊州市國土空間總體規(guī)劃(2021-2035年)
- 2024年政府辦事-戶口管理考試近5年真題集錦(頻考類試題)帶答案
- 鋰離子電池制造中的電池市場動態(tài)分析考核試卷
- 2024年內(nèi)蒙古中考語文試卷五套合卷附答案
- 園林綠化養(yǎng)護標(biāo)準及經(jīng)費測算
- 結(jié)構(gòu)力學(xué)本構(gòu)模型:粘彈性模型:粘彈性模型的數(shù)值模擬技術(shù)
- 2024年山東高考政治試卷
- SF-36生活質(zhì)量調(diào)查表(SF-36-含評分細則)
- DL-T5845-2021輸電線路巖石地基挖孔基礎(chǔ)工程技術(shù)規(guī)范
評論
0/150
提交評論