1、第 1 页 共 7 页南昌大学 2005 2006 学年第 1 学期期 末 考试试卷 试卷编号:12026 ( B )卷课程名称: 数据结构 适用班级: 自动化 03 级 姓名: 学号: 班级: 专业: 学院: 系别: 考试日期: 题号 一 二 三 四 五 六 七 八 九 十 总分题分 100累分人 签名得分一、 填空题(每空 2 分,共 18 分) 得分 评阅人1.1) is(are) the tree data structures.(树形结构)2) is(are) the graph data structures(图形结构)3) is(are) linear data structur
2、es(线性结构)2.according the following figures, is(are) the complete trees(完全二叉树 )is(are) the full trees(满二叉树).acb(b)Abccdgef(a)( c)adcb(d)ab de f第 2 页 共 7 页3. fig.1 is an example binary tree. Node _are leaves(叶子). The depth(深度) of e is _. The height of this tree is(这棵树的高度是 )_.4. the binary search tree p
3、roperty: all node stored in the left subtree of a node whose key value is K have key values _(less than/grater than/less than or equal to /grater than or equal to) K.二、简答题(共 46 分)得分 评阅人1 Determine O(.) for the following code fragments in the worst case.(计算时间复杂度)。( 每小题 4 分共 8 分)I=1;j=0;while (I+jj)j+
4、; else I+;(a)ab ccd e fg (c )(d)(f )(e)( b)fig(1)第 3 页 共 7 页(b) int low,mid,high;low=0; high=N-1;while(lowx)high=mid-1;else return mid;return NOTFOUND;2. finish the following implementation.(18)(程序填空,每空 2 分)a) Assume the queue is circular queue.inqueue functiontypedef structint dataMAXSIZE;int front
5、, rear;sequeue;sequeue squein(sequeue Q,int x)_ printf(“fulln“);exit(0); _;_; 第 4 页 共 7 页b) delete the ith element of the linked list.void listdel(linkedlist L, int i)linkedlist p,q;int j;p=L;j=1;while (_)p=p-next;j+;if(p-next=NULL|ji)printf(“position error“);exit(0);_;_;free(q);c) insert sort(assum
6、e array a contains n values).void inssort(int a, int n) int j,p,tmp;for(p=1;pn;p+)tmp=ap;for(j=p; _; j-)_3.The preorder enumeration for the binary tree (一棵二叉树的先序遍历是)is ABCDEFGH, And the inorder enumeration for the tree is(它的中序遍历是) CBEDAGHF. Draw the tree and the postorder enumeration for the tree is
7、_.(8)(画出这棵树并写出它的后序遍历)第 5 页 共 7 页4.if values are inserted in the order 120,42,42, 7, 2, 32, 37, 24,40.draw the Binary Search Trees for the collection of values. (6)(依次插入结点 120,42,42, 7, 2, 32, 37, 24,40,画出所形成的二叉查找树)5. build the Huffman tree for the message “CASTTATASA” and determine the Huffman codes
8、.(8)有一段电文“CASTTATASA” ,试设计赫夫曼编码(画出构造的赫夫曼树)三、程序设计(共 36 分)得分 评阅人1、 write a implementation to complete the following task. the main function are needed to write第 6 页 共 7 页1) write a function named TREENODE *creat_tree( ) to building the binary search tree (the node value is input from the keyboard. # m
9、eans the empty node.), and the write the character you input from the keyboard.2) write a function named postorder( ) to perform an postorder traversal of the tree 3) write the main program.USRY第 7 页 共 7 页2.write a c implementation which can complete the following task: first insert element x at the ith position of the the Array-based list (i=0,15). (在第 i 个位置上上插入元素)(18 分)seqlist sqinsert(seqlist L,int i,int x)then inverse the elements of array.(将数组中的元素逆置 )seqlist sqinv(seqlist L)typedef structint datamaxsize;int length;seqlist;