版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
「一入Java深似讲师信•劝退师,ApacheCloud••「一入Java深似讲师信•劝退师,ApacheCloud••••主要议•实•二分搜索算•Java二分搜索算法主要议•实•二分搜索算•Java二分搜索算法实•课程总•基本介Analgorithmthatputselementsofalistinacertainorder.Themostfrequentlyusedordersarenumericalorderandlexicographicalorder.基本介Analgorithmthatputselementsofalistinacertainorder.Themostfrequentlyusedordersarenumericalorderandlexicographicalorder.Efficientsortingisimportantforoptimizingtheefficiencyofotheralgorithms(suchassearchandmergealgorithms)whichrequireinputdatatobeinsortedlists.Sortingisalsooftenusefulforcanonicalizingdataandforproducinghuman-readableoutput.Moreformally,theoutputofanysortingalgorithmmustsatisfytwo•Theoutputisinnondecreasingorder(eachelementisnosmallerthanthepreviouselementaccordingtothedesiredtotalorder);•Theoutputisapermutation(areordering,yetretainingalloftheoriginalelements)ofthe•分••••稳定性:当相同的健存在时,经过排序后,其值也保持相对的顺序(不发生变化••分••••稳定性:当相同的健存在时,经过排序后,其值也保持相对的顺序(不发生变化••分••分••计算复杂度计算复杂度•Theamountofresourcesrequiredforrunningit.Thecomputationalcomplexityofaproblemistheminimumofthecomplexitiesofallpossiblealgorithmsforthisproblem(includingtheunknownalgorithms).Astheamountofneededresourcesvarieswiththeinput,thecomplexityisgenerallyexpressedasafunctionn→f(n),wherenisthesizeoftheinput,andf(n)iseithertheworst-casecomplexity,thatisthemaximumoftheamountofresourcesthatareneededforallinputsofsizen,ortheaverage-casecomplexity,thatisaverageoftheamountofresourcesoverallinputofsizen.计算复杂度计算复杂度•Whenthenatureoftheresourcesisnotexplicitlygiven,thisisusuallythetimeneededforrunningthealgorithm,andonetalksoftimecomplexity.However,thisdependsonthecomputerthatisused,andthetimeisgenerallyexpressedasthenumberofneededelementaryoperations,whicharesupposedtotakeaconstanttimeonagivencomputer,andtochangebyaconstantfactorwhenonechangesofcomputer.Otherwise,theresourcethatisconsideredisoftenthesizeofthememorythatisneeded,andonetalksofspacecomplexity.时间复杂度(时间复杂度(Time•Theamountoftimeittakestorunanalgorithm.Timecomplexityiscommonlyestimatedbycountingthenumberofelementaryoperationsperformedbythealgorithm,supposingthateachelementaryoperationtakesafixedamountoftimetoperform.Thus,theamountoftimetakenandthenumberofelementaryoperationsperformedbythealgorithmaretakentodifferbyatmostaconstantfactor.时间复杂度(时间复杂度(Time•Sinceanalgorithm'srunningtimemayvaryamongdifferentinputsofthesamesize,onecommonlyconsiderstheworst-casetimecomplexity,whichisthemaximumamountoftimerequiredforinputsofagivensize.Lesscommon,andusuallyspecifiedexplicitly,istheaverage-casecomplexity,whichistheaverageofthetimetakenoninputsofagivensize(thismakessensebecausethereareonlyafinitenumberofpossibleinputsofagivensize).Inbothcases,thetimecomplexityisgenerallyexpressedasafunctionofthesizeoftheinput.Sincethisfunctionisgenerallydifficulttocomputeexactly,andtherunningtimeforsmallinputsisusuallynotconsequential,onecommonlyfocusesonthebehaviorofthecomplexitywhentheinputsizeincreases—thatis,theasymptoticbehaviorofthe时间复杂度(Time•表达式:BigO•常量时间:T(n)O(1)(数组随机访问•线性时间:T(n)=O(n)(在未排序数组中找寻最值•时间复杂度(Time•表达式:BigO•常量时间:T(n)O(1)(数组随机访问•线性时间:T(n)=O(n)(在未排序数组中找寻最值•对数时间:T(n)=O(logn)(二进制搜索•指数时间:T(n)=O(n^c)(冒泡排序、插入排序•BigO••无限渐进•无限小渐进BigO••无限渐进•无限小渐进•稳定性稳定性•Stablesortalgorithmssortrepeatedelementsinthesameorderthattheyappearintheinput.Whensortingsomekindsofdata,onlypartofthedataisexaminedwhendeterminingthesortorder.Forexample,inthecardsortingexampletotheright,thecardsarebeingsortedbytheirrank,andtheirsuitisbeingignored.Thisallowsthepossibilityofmultipledifferentcorrectlysortedversionsoftheoriginallist.Stablesortingalgorithmschooseoneofthese,accordingtothefollowingrule:iftwoitemscompareasequal,likethetwo5cards,thentheirrelativeorderwillbepreserved,sothatifonecamebeforetheotherintheinput,itwillalsocomebeforetheotherintheoutput.稳定性••稳定性••稳定性••稳定性••比较排•Acomparisonsortisatypeofsortingalgorithmthatonlyreadsthelistelementsthroughasingleabstractcomparison比较排•Acomparisonsortisatypeofsortingalgorithmthatonlyreadsthelistelementsthroughasingleabstractcomparisonoperation(oftena"lessthanorequalto"operatororathree-waycomparison)thatdetermineswhichoftwoelementsshouldoccurfirstinthefinalsortedlist.Theonlyrequirementisthattheoperatorobeytwoofthepropertiesofatotalifa≤bandb≤cthena≤cforallaandb,eithera≤borb≤a(totalnessor比较排•冒泡排序(BubbleSort):最佳O(n)、平均O(n^2)、最坏•插入排序(InsertionSort):最佳O(n)、平均O(n^2)、最坏•快速排序(QuickSort):最佳O(nlogn)、平均比较排•冒泡排序(BubbleSort):最佳O(n)、平均O(n^2)、最坏•插入排序(InsertionSort):最佳O(n)、平均O(n^2)、最坏•快速排序(QuickSort):最佳O(nlogn)、平均O(nlogn)、最坏•合并排序(MergeSort):最佳O(nlogn)、平均O(nlogn)、最坏•Tim排序(TimSort):最佳O(n)、平均O(nlogn)、最坏•冒泡排序(Bubble•时间复杂度:最佳O(n)、平均O(n^2)冒泡排序(Bubble•时间复杂度:最佳O(n)、平均O(n^2)、最坏••插入排序(Insertion•时间复杂度:最佳O(n)、平均O(n^2)插入排序(Insertion•时间复杂度:最佳O(n)、平均O(n^2)、最坏••快速排序(Quick•时间复杂度:最佳O(nlogn)、平均O(nlogn)、最坏••获取pivot(轴•分区快速排序(Quick•时间复杂度:最佳O(nlogn)、平均O(nlogn)、最坏••获取pivot(轴•分区•递归•快速排序(Quick快速排序(Quick••合并排序(Merge•时间复杂度:最佳O(nlogn)、平均O(nlogn)、最坏••分块合并排序(Merge•时间复杂度:最佳O(nlogn)、平均O(nlogn)、最坏••分块•递归合并•合并排序(Merge合并排序(Merge••Tim排序•时间复杂度:最佳O(n)、平均O(nlogn)、最坏Tim排序•时间复杂度:最佳O(n)、平均O(nlogn)、最坏••实实集合框实内建实•冒泡排序•插入排序(7时•快速排序•合并排序Sort):java.util.Arrays#mergeSort集合框实内建实•冒泡排序•插入排序(7时•快速排序•合并排序Sort):java.util.Arrays#mergeSort之后需要激活•Tim排序•二分搜索(Binary二分搜索(Binary•Alsoknownashalf-intervalsearch,logarithmicsearch,orbinarychop,isasearchalgorithmthatfindsthepositionofatargetvaluewithinasortedarray.Binarysearchcomparesthetargetvaluetothemiddleelementofthearray.Iftheyarenotequal,thehalfinwhichthetargetcannotlieiseliminatedandthesearchcontinuesontheremaininghalf,againtakingthemiddleelementtocomparetothetarget
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 锅炉本体检修工安全教育模拟考核试卷含答案
- 调理肉制品加工工安全实操竞赛考核试卷含答案
- 植保机械操作工安全生产基础知识模拟考核试卷含答案
- 废矿物油再生处置工冲突管理知识考核试卷含答案
- 金箔制作工安全培训效果强化考核试卷含答案
- 氯甲烷生产工安全素养水平考核试卷含答案
- 硫回收装置操作工达标水平考核试卷含答案
- 皮具制作工岗前核心管理考核试卷含答案
- 纤维碳化装置操作工安全意识强化模拟考核试卷含答案
- 2024年毕节医学高等专科学校辅导员考试笔试真题汇编附答案
- 2026年冀教版初一地理上册期末真题试卷+解析及答案
- 2026年孝昌县供水有限公司公开招聘正式员工备考题库及答案详解参考
- 2025年文化产业版权保护与运营手册
- 四川省乐山市高中高三上学期第一次调查研究考试数学试题【含答案详解】
- 《创新创业基础》课件-项目1:创新创业基础认知
- 2026年初一寒假体育作业安排
- 物流行业运输司机安全驾驶与效率绩效评定表
- 2026北京市通州区事业单位公开招聘工作人员189人笔试重点基础提升(共500题)附带答案详解
- 2025~2026学年山东省菏泽市牡丹区第二十一初级中学八年级上学期期中历史试卷
- 2026国家统计局仪征调查队招聘辅助调查员1人(江苏)考试参考试题及答案解析
- 水利工程施工质量检测方案
评论
0/150
提交评论