一入深似海系列课程-二期四节集合框架算法运用_第1页
一入深似海系列课程-二期四节集合框架算法运用_第2页
一入深似海系列课程-二期四节集合框架算法运用_第3页
一入深似海系列课程-二期四节集合框架算法运用_第4页
一入深似海系列课程-二期四节集合框架算法运用_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

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

文档简介

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

评论

0/150

提交评论