




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
四川大学期末考试试题(2007-2008学年第1学期)课程号:课程名称:数据结构与算法分析(B卷) 任课教师: 适用专业年级:06级软件工程学号: 姓名: 考试须知四川大学学生参加由学校组织或由学校承办的各级各类考试,必须严格执行《四川大学考试工作管理办法》和《四川大学考场规则》。有考试违纪作弊行为的,一律按照《四川大学学生考试违纪作弊处罚条例》进行处理。四川大学各级各类考试的监考人员,必须严格执行《四川大学考试工作管理办法》、《四川大学考场规则》和《四川大学监考人员职责》。有违反学校有关规定的,严格按照《四川大学教学事故认定及处理办法》进行处理。题号1234567卷面成绩得分20101015151515阅卷教师阅卷时间1.Single-Choicequestions(eachquestion2scores,total20scores)(1)Theprimarypurposeofmostcomputerprogramsisa)toperformamathematicalcalculation.b)tostoreandretrieveinformation.c)tosortacollectionofrecords.d)alloftheabove.(2)AssumethatPcontainsnelements.ThenumberofsetsinthepowersetofPisa)n b)n^2c)2^n d)2^n-1e)2^n+1(3)Pickthegrowthratethatcorrespondstothemostefficientalgorithmasngetslarge:a)5n b)20lognc)2n^2 d)2^n(4)Asequencehasthefollowingproperties:a)Mayhaveduplicates,elementhaveaposition.b)Mayhaveduplicates,elementsdonothaveaposition.c)Maynothaveduplicates,elementshaveaposition.d)Maynothaveduplicates,elementsdonothaveaposition.(5)ThecorrecttraversaltouseonaBSTtovisitthenodesinsortedorderis:a)Preordertraversal. b)Inordertraversal.c)Postordertraversal.(6)Whensortingnrecords,Insertionsorthasbest-casecost:a)O(logn). b)O(n).c)O(nlogn). d)O(n^2)e)O(n!) f)Noneoftheabove.(7)Foralistoflengthn,thelinked-listimplementation'sprevfunctionrequiresworst-casetime:a)O(1).b)O(logn).c)O(n).d)O(n^2).(8)Theeasiestwaytorepresentageneraltreeisto:a)converttoalist. b)converttoabinarytree.c)converttoagraph.(9)Depth-firstsearchisbestimplementedusing:a)Astackorrecursion. b)Aqueue.c)Atree.(10)ForsetP,thenotation|P|indicatesa)ThenumberofelementsinP. b)TheinverseofP.c)ThepowersetofP. d)Noneoftheabove.2.(10scores)WriteaseriesofC++statementsthatusestheListADTasfollowstocreatealistcapableofholdingtwentyelementsandwhichactuallystoresthelistwithfollowingconfiguration:<6,28|18,8,19>solution:listL1(20);L1.append(6);L1.append(28);L1.append(18);L1.append(8);L1.append(9);L1.next();L1.next();//Listabstractclasstemplate<classElem>classList{public://Reinitializethelist.Theclientisresponsiblefor//reclaimingthestorageusedbythelistelements.virtualvoidclear()=0;//Insertanelementatthefrontoftherightpartition.//Returntrueifsuccessful,falseifthelistisfull.virtualboolinsert(constElem&)=0;//Appendanelementattheendoftherightpartition.//Returntrueifsuccessful,falseifthelistisfull.virtualboolappend(constElem&)=0;//Removethefirstelementofrightpartition.Return//trueifsuccessful,falseifrightpartitionisempty.//Theelementremovedisreturnedintheparameter.virtualboolremove(Elem&)=0;//Placefenceatliststart,makingleftpartitionemptyvirtualvoidsetStart()=0;//Placefenceatlistend,makingrightpartitionemptyvirtualvoidsetEnd()=0;//Movefenceonestepleft;nochangeifalreadyatstartvirtualvoidprev()=0;//Movefenceonestepright;nochangeifalreadyatendvirtualvoidnext()=0;//ReturnlengthofleftpartitionvirtualintleftLength()const=0;//ReturnlengthofrightpartitionvirtualintrightLength()const=0;//Ifposormoreelementsareinthelist,setthesize//ofleftpartitiontoposandreturntrue.Otherwise,//donothingandreturnfalse.virtualboolsetPos(intpos)=0;//Returninfirstparameterthefirstelementofthe//rightpartition.Returntrueifsuccessful,false//iftherightpartitionisempty.virtualboolgetValue(Elem&)const=0;//Printthecontentsofthelistvirtualvoidprint()const=0;};3.(10scores)BuildtheHuffmancodingtreeanddeterminethecodesforthefollowingsetoflettersandweights:a b c d e.1 3 5 7 11solution:Huffmancodingtreeasfollows:Herearethefinalcodes.a11111b1110c110d10e04.(15scores)Whataretheminimumandmaximumnumberofelememtsinaheapofheighth?solution:Theminimumnumberofelementsiscontainedintheheapwithasinglenodeatdepthh-1,foratotalof2h-1nodes.Themaximumnumberofelementsiscontainedintheheapthathascompletelyfilleduplevelh-1,foratotalof2h-1nodes.5.(15scores)TheBubbleSortimplentationhasthefollowinginnerforloop:for(intj=n–1;j>i;j--)Considertheeffectofreplacingthiswiththefollowingstaement:for(intj=n–1;j>0;j--)Wouldthenewimplementationworkcorrectly?Wouldthechangeaffecttheasymptoticcomplexityofthealgorithm?Howwouldthechangeaffecttherunningtimeofthealgorithm?solution:Therevisedalgorithmwillworkcorrectly,anditsasymptoticcomplexitywillremainΘ(n2).However,itwilldoabouttwiceasmanycomparisons,sinceitwillcompareadjacentelementswithintheportionofthelistalreadyknowntobesorted.Theseadditionalcomparisonsareunproductive.6.(15scores)//Binarytreenodeabstractclasstemplate<classElem>classBinNode{public://Returnthenode'selementvirtualElem&val()=0;//Setthenode'selementvirtualvoidsetVal(constElem&)=0;//Returnthenode'sleftchildvirtualBinNode*left()const=0;//Setthenode'sleftchildvirtualvoidsetLeft(BinNode*)=0;//Returnthenode'srightchildvirtualBinNode*right()const=0;//Setthenode'srightchildvirtualvoidsetRight(BinN
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 财务数据透明度提升方案计划
- 心智成长班主任的心智成长计划
- 化工行业保安工作总结计划
- 年度市场分析与策略指导计划
- 生物经典实验分享与讨论方案计划
- 学期教学工作总结报告内容布置总结安排计划
- 小学生心理健康与品德教育的关系计划
- 市政设施的安全管理与维护计划
- 班级特色活动的策划与设计计划
- Unit 1 wrapping up the topic-Project 教学设计 2024-2025学年仁爱科普版(2024)七年级英语上册
- GB/T 11766-2008小米
- 初中英语语法大全知识点总结可打印
- 医患沟通技巧培训试题及答案
- FANUCROBOSHOTSi注塑机操作说明书学习课件
- 2023辽宁医药职业学院单招数学模拟试题(附答案解析)
- 变更风险识别、评估记录表参考模板范本
- 南京长安汽车有限公司环保搬迁(置换升级)项目环境影响报告表
- 人工挖孔桩施工危险源辨识与评价及应对措施
- 品管圈成果汇报——提高导管固定正确率PPT课件
- 2018年真分数假分数PPT课件
- 及成品SN编码规则
评论
0/150
提交评论