计算机科学导论PPT幻灯片.pptx_第1页
计算机科学导论PPT幻灯片.pptx_第2页
计算机科学导论PPT幻灯片.pptx_第3页
计算机科学导论PPT幻灯片.pptx_第4页
计算机科学导论PPT幻灯片.pptx_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

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

文档简介

1.1,Objectives:,1.2,Objectives(continued):,1.3,1.4,8.1Concept,Inthissectionweinformallydefineanalgorithmandelaborateontheconceptusinganexample.,Figure8.1:Informaldefinitionofanalgorithm,1.5,Figure8.2:Findingthelargestintegeramongfiveintegers,1.6,Figure8.3:DefiningactionsinFindLargestalgorithm,1.7,Figure8.4:FindLargestrefined,1.8,Figure8.5:GeneralizationofFindLargest,1.9,1.10,8.2Threeconstructs,Computerscientistshavedefinedthreeconstructsforastructuredprogramoralgorithm.Theideaisthataprogrammustbemadeofacombinationofonlythesethreeconstructs:sequence,decision(selection),andrepetition.Ithasbeenproventhereisnoneedforanyotherconstructs.Usingonlytheseconstructsmakesaprogramoranalgorithmeasytounderstand,debug,orchange.,Figure8.6:Threeconstructs,1.11,1.12,8.3AlgorithmRepresentation,Sofar,wehaveusedfigurestoconveytheconceptofanalgorithm.Duringthelastfewdecades,toolshavebeendesignedforthispurpose.Twoofthesetools,UMLandpseudocode,arepresentedhere.,Figure8.7:UMLforthreeconstructs,1.13,Figure8.8:Pseudocodeforthreeconstructs,1.14,Algorithm8.1:Calculatingthesumoftwointegers:,1.15,Algorithm8.2:Assigningpass/nopassgrade:,1.16,Algorithm8.3:Assigningalettergrade:,1.17,Algorithm8.4:Findingthelargestinteger:,1.18,Algorithm8.5:Findthesmallestintegersamong1000:,1.19,1.20,8.4AMoreFormalDefinition,Nowthatwehavediscussedtheconceptofanalgorithmandshownitsrepresentation,hereisamoreformaldefinition.Letuselaborateonthisdefinition.,1.21,8.5BasicAlgorithms,Severalalgorithmsareusedincomputersciencesoprevalentlythattheyareconsidered“basic”.Wediscussthemostcommonhere.Thisdiscussionisverygeneral:implementationdependsonthelanguage.,Figure8.9:Summationalgorithm,1.22,Figure8.10:Productalgorithm,1.23,Figure8.11:Selectionsort,1.24,Figure8.12:Exampleofselectionsort,1.25,Figure8.13:Selectionsortalgorithm,1.26,Figure8.14:Bubblesort,1.27,Figure8.15:Exampleofbubblesort,1.28,Figure8.16:Insertionsort,1.29,Figure8.17:Exampleofinsertionsort,1.30,Figure8.18:Anexampleofasequentialsearch,1.31,Figure8.19:Exampleofabinarysearch,1.32,1.33,8.6Subalgorithms,Thethreeprogrammingconstructsdescribedearlierallowustocreateanalgorithmforanysolvableproblem.Theprinciplesofstructuredprogramming,however,requirethatanalgorithmbebrokenintosmallunitscalledsubalgorithms.Eachsubalgorithmisinturndividedintosmallersubalgorithms.,Figure8.20:Conceptofasubalgorithm,1.34,1.35,8.7Recursion,Ingeneral,therearetwoapproachestowritingalgorithmsforsolvingaproblem.Oneusesiteration,theotherusesrecursion.Recursionisaprocessinwhichanalgorithmcallsitself.,Figure8.21:Iterativedefinitionoffactorial,1.36,Figure8.22:Recursivedefinitionoffactorial,1.37,Figure8.23:Tracingtherecursives

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论