软件学院数据结构与算法分析期末试题(2006级B)_第1页
软件学院数据结构与算法分析期末试题(2006级B)_第2页
软件学院数据结构与算法分析期末试题(2006级B)_第3页
软件学院数据结构与算法分析期末试题(2006级B)_第4页
软件学院数据结构与算法分析期末试题(2006级B)_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

四川大学期末考试试题(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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论