已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025中车大连机车车辆限公司招聘高校毕业生170人易考易错模拟试题(共500题)试卷后附参考答案
- 2025中建一局一公司广东分公司招聘BIM工程师若干名易考易错模拟试题(共500题)试卷后附参考答案
- 公共养老服务建设项目节能评估报告
- 太乙火锅活动策划方案(3篇)
- 运输防疫消毒管理制度内容(3篇)
- IA应急预案汇编(3篇)
- 庭院水系施工方案(3篇)
- 军营超市应急预案(3篇)
- 施工阶段环境保护措施
- 2025年安徽教师招考试题及答案
- 2025山西忻州市原平市招聘社区专职工作人员50人考试历年真题汇编附答案解析
- 中药煎煮知识与服用方法
- 2026东莞银行秋季校园招聘备考题库及答案详解(基础+提升)
- 消防水泵房管理制度及操作规程
- IABP在心源性休克中的个体化撤机方案制定
- 2025内蒙古呼伦贝尔农垦谢尔塔拉农牧场有限公司招聘笔试历年参考题库附带答案详解
- 野战军生存课件
- 2025年4月自考《市场营销学》真题(完整试题)含答案
- 《民航概论》期末考试复习题库(附答案)
- 化工企业冬季风险防控与异常工况处置实践
- 兰城院田径运动讲义05田径运动竞赛的组织与编排
评论
0/150
提交评论