版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Unit8DatastructureByWucanghai1.OverviewofDataStructuresOnceyou'velearnedtoprogram,yourunintoreal-worldproblemsthatrequiremorethanaprogramminglanguagealonetosolve.注1DataStructuresandAlgorithmsinJavaisagentleimmersion(3)intothemostpractical(4)waystomakedatadowhatyouwantittodo.注2注1:这句话的含义是:当你学编程的时候,你遇到的现实的问题就是每一种编程语言单独的存储数据。注2:这句话的含义是:基于Java的数据结构与算法是把数据按你想要的方式存储的最实用的方式。TextADatastructure(1)sandalgorithm(2)sinjavaAnotherwaytolookatdatastructuresistofocusontheirstrengthsandweaknesses.Inthissectionwe'llprovideanoverview,intheformof(5)atable,ofthemajordatastoragestructureswe'llbediscussing.DataStructureAdvantagesDisadvantagesArrayQuickinsertion,veryfastaccessifindexknownSlowsearch,slowdeletion,fixedsize.注3OrderedarrayQuickersearchthanunsortedarraySlowinsertionanddeletion,fixedsize.StackProvideslast-in,first-outaccess.SlowaccesstootheritemsLinkedlistQuickinsertion,quickdeletionSlowsearchBinarytreeQuicksearch,insertion,deletion(iftreeremainsbalanced)Deletionalgorithmiscomplex.注4Red-blacktreeQuicksearch,insertion,deletion.Treealwaysbalanced.ComplexHashtableVeryfastaccessifkeyknown.Fastinsertion.Slowdeletion,accessslowifkeynotknown,inefficientmemoryusage.注5GraphModelsreal-worldsituations.Somealgorithmsareslowandcomplex.注62.OverviewofAlgorithms
Manyofthealgorithmswe'lldiscussapplydirectlytospecificdatastructures.Formostdatastructures,youneedtoknowhowto(1)Insertanewdataitem.(2)Searchforaspecifieditem.(3)Deleteaspecifieditem.
Youmayalsoneedtoknowhowtoiteratethroughalltheitemsinadatastructure,visitingeachoneinturnsoastodisplayitorperformsomeotheractiononit.Oneimportantalgorithmcategory(7)issorting.Therearemanywaystosortdata,Theconceptofrecursionisimportantindesigningcertainalgorithms(1)ProblemswithProcedural(9)Languages
OOPwasinventedbecauseprocedurallanguages,suchasC,Pascal,andBASIC,werefoundtobeinadequate(10)forlargeandcomplexprograms.Whywasthis?3.Object-OrientedProgrammingTheproblemshavetodowiththeoverallorganizationoftheprogram.Proceduralprogramsareorganizedbydividingthecodeintofunctions(calledproceduresorsubroutinesinsomelanguages).注7Groupsoffunctionscouldformlargerunitscalledmodulesorfiles.CrudeOrganizationalUnitsOnedifficultywiththiskindoffunction-basedorganizationwasthatitfocusedonfunctionsattheexpenseofdata.Thereweren'tmanyoptionswhenitcametodata.Tosimplifyslightly,datacouldbelocaltoaparticularfunctionoritcouldbeglobal—accessible(11)toallfunctions.Therewasnoway(atleastnotaflexibleway)tospecifythatsomefunctionscouldaccessavariable(12)andotherscouldn't.Thiscausedproblemswhenseveralfunctionsneededtoaccessthesamedata.Tobeavailabletomorethanonefunction,suchvariableshadtobeglobal,butglobaldatacouldbeaccessedinadvertently(13)byanyfunctionintheprogram.注8Thisleadstofrequentprogrammingerrors.Whatwasneededwasawaytofine-tunedataaccessibility,allowinvariablestobeavailabletofunctionswithaneedtoaccessit,buthidingitfromothers.FromTheideaofobjectsaroseintheprogrammingcommunityasasolutiontotheproblemswithprocedurallanguages.4.ObjectsinaNutshellThisnewentity(14),theobject,solvesseveralproblemssimultaneously(15).Notonlydoesaprogrammingobjectcorrespondmoreaccurately(16)toobjectsintherealworld,italsosolvestheproblemengenderedby(17)globaldataintheproceduralmodel.
注9(1)Objects
Youmightthinkthattheideaofanobjectwouldbeenoughforoneprogrammingrevolution(18),butthere'smore.
注10Earlyon,itwasrealizedthatyoumightwanttomakeseveralobjectsofthesametype.Maybeyou'rewritingafurnacecontrolprogram(19)foranentireapartmenthouse,forexample,andyouneedseveraldozenthermostatobjects(20)inyourprogram.(2)ClassesItseemsashametogotothetroubleofspecifyingeachoneseparately(21).Thus,theideaofclasseswasborn。WordsandPhrasesaccessibleaccuratelycategorycharacteristicentityimmersioninadequateinadvertently可以访问的准确地分类,类别特性,特点实体,实数沉浸;浸没;浸不满意的,不足的不经意的,随意的WordsandPhrasesorientpracticalproceduralrevolutionseparatelysimultaneouslystructurevariable面向….的,朝向实用的过程的革命分别地同时地结构体[数]变量
TextBTheintroductionoftwoimportantdatastructures
Inthispartwewilltakeabriefintroductionabouttwoimportantdatastructures,LinkedlistandHashtable,whichwillmakeiteffectivetosearchorstorethedata.1.Linked(1)listWesawthatarrayshadcertaindisadvantagesasdatastoragestructures.Inanunorderedarray,searchingisslow,whereasinanorderedarray,insertionisslow.注1Inbothkindsofarraysdeletionisslow.Also,thesizeofanarraycan'tbechangedafterit'screated.Inthispartwe'lllookatadatastoragestructurethatsolvessomeoftheseproblems:thelinkedlist.Linkedlistsareprobablythesecondmostcommonlyusedgeneral-purposestoragestructuresafterarrays.Thelinkedlistisaversatile(2)mechanism(3)suitableforuseinmanykindsofgeneral-purposedatabases.Itcanalsoreplaceanarrayasthebasisforotherstoragestructuressuchasstacksandqueues.易变的,灵活的机制
Infact,youcanusealinkedlistinmanycaseswhereyouuseanarray(unlessyouneedfrequentrandomaccess(4)toindividualitemsusinganindex).Linkedlistsaren'tthesolutiontoalldatastorageproblems,buttheyaresurprisinglyversatileandconceptually(5)simplerthansomeotherpopularstructuressuchastrees.
注2We'llinvestigate(6)theirstrengthsandweaknessesaswegoalong.Inthissectionwewillrefertotwoveryusefuldatastructure.随机存取概念上的探讨,投入2.LinksInalinkedlist,eachdataitemisembeddedinalink.AlinkisanobjectofaclasscalledsomethinglikeLink.Becausetherearemanysimilarlinksinalist,itmakessensetouseaseparateclassforthem,distinct(7)fromthelinkedlistitself.注3Eachlinkobjectscontainsareference(usuallycallednext)tothenextlinkinthelist.Afieldinthelistitselfcontainsarereferencetothefirstlink.Here'spartofthedefinitionofaclassLink.Itcontainssomedataandareferencetothenextlink.classLink{publicintiData;//datapublicdoubledData;//datapublicLinknext;//referencetonextlink}Thiskindofclassdefinitionissometimescalledself-referentialbecauseitcontainsafield—callednextinthiscase—ofthesametypeasitself.注53.Hash(8)Tables
Ahashtableisadatastructurethatoffersveryfastinsertionandsearching.Whenyoufirsthearaboutthem,hashtablessoundalmosttoogoodtobetrue.Nomatterhowmanydataitemsthereare,insertionandsearching(andsometimesdeletion)cantakecloseto(9)constanttime:O(1)inBigOnotation.注6Inpracticethisisjustafewmachineinstructions.Forahumanuserofahashtablethisisessentially(10)instantaneous.It'ssofastthatcomputerprogramstypicallyusehashtableswhentheyneedtolookuptensofthousandsofitemsinlessthanasecond(asinspellingcheckers).Hashtablesaresignificantly(11)fasterthantreesNotonlyaretheyfast,hashtablesarerelatively(12)easytoprogr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国单孔子单把面盆水咀市场调查研究报告
- 2024版设备购买协议
- 2025年度疫情防控应急物资储备中心n95口罩采购合同范本3篇
- 二零二五年度货运司机劳务派遣合同3篇
- 2025年度大豆绿色种植推广合作合同范本3篇
- 2025年度绿色有机西瓜产地直销合作合同范本3篇
- 2025年度不锈钢板材国际贸易结算及风险管理合同3篇
- 2024行政合同争议调解程序:如何有效运用行政优先权3篇
- 2025年度WPS合同管理平台定制开发与实施合同3篇
- 二零二五年甘肃离岗创业人员社保接续与待遇保障合同3篇
- 中国的世界遗产智慧树知到期末考试答案2024年
- 2023年贵州省铜仁市中考数学真题试题含解析
- 世界卫生组织生存质量测量表(WHOQOL-BREF)
- 《叶圣陶先生二三事》第1第2课时示范公开课教学PPT课件【统编人教版七年级语文下册】
- 某送电线路安全健康环境与文明施工监理细则
- GB/T 28885-2012燃气服务导则
- PEP-3心理教育量表-评估报告
- 控制性详细规划编制项目竞争性磋商招标文件评标办法、采购需求和技术参数
- 《增值税及附加税费申报表(小规模纳税人适用)》 及其附列资料-江苏税务
- 中南民族大学中文成绩单
- 危大工程安全管理措施方案
评论
0/150
提交评论