ImageVerifierCode 换一换
格式:DOCX , 页数:8 ,大小:30.94KB ,
资源ID:23102705      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23102705.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(软件学院数据结构与算法分析期末试题B.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

软件学院数据结构与算法分析期末试题B.docx

1、软件学院数据结构与算法分析期末试题B四川大学期末考试试题(2007-2008学年第1学期)课程号: 课程名称: 数据结构与算法分析(B卷) 任课教师: 适用专业年级: 06级软件工程 学号: 姓名: 考试须知四川大学学生参加由学校组织或由学校承办的各级各类考试,必须严格执行四川大学考试工作管理办法和四川大学考场规则。有考试违纪作弊行为的,一律按照四川大学学生考试违纪作弊处罚条例进行处理。四川大学各级各类考试的监考人员,必须严格执行四川大学考试工作管理办法、四川大学考场规则和四川大学监考人员职责。有违反学校有关规定的,严格按照四川大学教学事故认定及处理办法进行处理。题 号1234567卷面成绩得

2、 分20101015151515阅卷教师阅卷时间1. Single-Choice questions(each question 2 scores, total 20 scores)(1)The primary purpose of most computer programs is a) to perform a mathematical calculation. b) to store and retrieve information. c) to sort a collection of records. d) all of the above.(2)Assume that P cont

3、ains n elements. The number of sets in the powerset of P isa) n b) n2c) 2n d) 2n - 1e) 2n + 1(3)Pick the growth rate that corresponds to the most efficientalgorithm as n gets large:a) 5n b) 20 log nc) 2n2 d) 2n(4)A sequence has the following properties:a) May have duplicates, element have a position

4、.b) May have duplicates, elements do not have a position.c) May not have duplicates, elements have a position.d) May not have duplicates, elements do not have a position.(5)The correct traversal to use on a BST to visit the nodes in sorted order is:a) Preorder traversal. b) Inorder traversal.c) Post

5、order traversal.(6)When sorting n records, Insertion sort has best-case cost:a) O(log n). b) O(n).c) O(n log n). d) O(n2)e) O(n!) f) None of the above.(7)For a list of length n, the linked-list implementations prev function requires worst-case time:a) O(1).b) O(log n).c) O(n).d) O(n2).(8)The easiest

6、 way to represent a general tree is to:a) convert to a list. b) convert to a binary tree.c) convert to a graph.(9)Depth-first search is best implemented using:a) A stack or recursion. b) A queue.c) A tree.(10)For set P, the notation |P| indicatesa) The number of elements in P. b) The inverse of P.c)

7、 The powerset of P. d) None of the above.2(10 scores)Write a series of C+ statements that uses the List ADT as follows to create a list capable of holding twenty elements and which actually stores the list with following configuration:solution:list L1(20);L1.append(6);L1.append(28);L1.append(18);L1.

8、append(8);L1.append(9);L1.next();L1.next();/ List abstract classtemplate class List public: / Reinitialize the list. The client is responsible for / reclaiming the storage used by the list elements. virtual void clear() = 0; / Insert an element at the front of the right partition. / Return true if s

9、uccessful, false if the list is full. virtual bool insert(const Elem&) = 0; / Append an element at the end of the right partition. / Return true if successful, false if the list is full. virtual bool append(const Elem&) = 0; / Remove the first element of right partition. Return / true if successful,

10、 false if right partition is empty. / The element removed is returned in the parameter. virtual bool remove(Elem&) = 0; / Place fence at list start, making left partition empty virtual void setStart() = 0; / Place fence at list end, making right partition empty virtual void setEnd() = 0; / Move fenc

11、e one step left; no change if already at start virtual void prev() = 0; / Move fence one step right; no change if already at end virtual void next() = 0; / Return length of left partition virtual int leftLength() const = 0; / Return length of right partition virtual int rightLength() const = 0; / If

12、 pos or more elements are in the list, set the size / of left partition to pos and return true. Otherwise, / do nothing and return false. virtual bool setPos(int pos) = 0; / Return in first parameter the first element of the / right partition. Return true if successful, false / if the right partitio

13、n is empty. virtual bool getValue(Elem&) const = 0; / Print the contents of the list virtual void print() const = 0;3(10 scores)Build the Huffman coding tree and determine the codes for the following set of letters and weights:a b c d e.1 3 5 7 11solution:Huffman coding tree as follows:Here are the

14、final codes.a 11111b 1110c 110d 10e 04(15 scores)What are the minimum and maximum number of elememts in a heap of height h ?solution:The minimum number of elements is contained in the heap with a single nodeat depth h - 1, for a total of 2h-1 nodes.The maximum number of elements is contained in the

15、heap that has completely filled up level h - 1, for a total of 2h - 1 nodes.5(15 scores)The Bubble Sort implentation has the following inner for loop:for (int j = n 1; j i; j-)Consider the effect of replacing this with the following staement:for (int j = n 1; j 0; j-)Would the new implementation wor

16、k correctly? Would the change affect the asymptotic complexity of the algorithm? How would the change affect the running time of the algorithm?solution:The revised algorithm will work correctly, and its asymptotic complexity willremain(n2). However, it will do about twice as many comparisons, since

17、it will compare adjacent elements within the portion of the list already known to be sorted. These additional comparisons are unproductive.6(15 scores)/ Binary tree node abstract classtemplate class BinNode public: / Return the nodes element virtual Elem& val() = 0; / Set the nodes element virtual v

18、oid setVal(const Elem&) = 0; / Return the nodes left child virtual BinNode* left() const = 0; / Set the nodes left child virtual void setLeft(BinNode*) = 0; / Return the nodes right child virtual BinNode* right() const = 0; / Set the nodes right child virtual void setRight(BinNode*) = 0; / Return tr

19、ue iff the node is a leaf virtual bool isLeaf() = 0;Write a recursive function that returns a count of the number of leaf nodes in a binary true.solution:template int count(BinNode* subroot) if (subroot = NULL) return 0; / Empty subtreeif (subroot-isLeaf() return 1; / A leafreturn 1 + count(subroot-left() +count(subroot-right();7(15 scores)List the order in which the edges of the following graph are visited when running Kruskals MST algorithm. Show the final MST.solution:(1, 6) (6, 5) (2, 3) (2, 4) (4, 6).Alternatively, (1, 6) (6, 5) (2, 3) (2, 4) (1, 2).etc

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1