




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
四川大学期末考试试题(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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辽宁政法职业学院《线性代数》2023-2024学年第二学期期末试卷
- 永州职业技术学院《文学经典导读》2023-2024学年第二学期期末试卷
- 2025届安徽省庐巢七校高考模拟试卷(4)历史试题含解析
- 2025年福建省三明市三地三校高考模拟金典卷物理试题(六)试题含解析
- 湖南大学《音乐基础理论1》2023-2024学年第一学期期末试卷
- 湖南省“五市十校”2024-2025学年高三下学期摸底语文试题含解析
- 辽宁工程职业学院《中国风景园林艺术之源流》2023-2024学年第二学期期末试卷
- 酒店餐饮服务管理
- 静电危害知识培训
- 财务财产安全案例分享
- 中建二测考试题库及答案
- 沙特阿拉伯2030年愿景
- 《现代汉语》课件-词类(下)
- 肿瘤发生的分子机制课件
- 2024小学语文新教材培训:一年级语文教材的修订思路和主要变化
- 2024-2030年中国五星级酒店产业未来发展趋势及投资策略分析报告
- 2024-2030年白酒零售产业规划专项研究报告
- 浙江宁波人才发展集团有限公司招聘笔试题库2024
- 《国土空间规划》-实验教学大纲
- 小学语文六年级下册单元作文评价表:让真情自然流露
- 七年级下册数学课件:平行线中的拐点问题
评论
0/150
提交评论