下载此文档

第02章基本数据结构stacksqueuesliststrees教学提纲.ppt


文档分类:IT计算机 | 页数:约30页 举报非法文档有奖
1/30
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/30 下载此文档
文档列表 文档介绍
ElementaryDataStructuresStacks,Queues,&ListsAmortizedanalysisTrees1ElementaryDataStructuresTheStackADT(§)TheStackADTstoresarbitraryobjectsInsertionsanddeletionsfollowthelast-infirst-outschemeThinkofaspring-loadedplatedispenserMainstackoperations:push(object):insertsanelementobjectpop():removesandreturnsthelastinsertedelementAuxiliarystackoperations:objecttop():returnsthelastinsertedelementwithoutremovingitintegersize():returnsthenumberofelementsstoredbooleanisEmpty():indicateswhethernoelementsarestored2ElementaryDataStructuresApplicationsofStacksDirectapplicationsPage-visitedhistoryinaWebbrowserUndosequenceinatexteditorChainofmethodcallsintheJavaVirtualMachineorC++ponentofotherdatastructures3ElementaryDataStructuresArray-basedStack(§)AsimplewayofimplementingtheStackADTusesanarrayWeaddelementsfromlefttorightAvariabletkeepstrackoftheindexofthetopelement(sizeist+1)S012t…Algorithmpop(): ifisEmpty()then throwEmptyStackException else tt1 returnS[t+1]Algorithmpush(o) ift=1then throwFullStackException else tt+1 S[t]paretheincrementalstrategyandthedoublingstrategybyanalyzingthetotaltimeT(n)neededtoperformaseriesofnpushoperationsWeassumethatwestartwithanemptystackrepresentedbyanarrayofsize1Wecallamortizedtimeofapushoperationtheaveragetimetakenbyapushovertheseriesofoperations,.,T(n)/n6ElementaryDataStructuresAnalysisoftheIncrementalStrategyWereplacethearrayk=n/ctimesThetotaltimeT(n)ofaseriesofnpushoperationsisproportionalton+c+2c+3c+4c+…+kc=n+c(1+2+3+…+k)=n+ck(k+1)/2Sincecisaconstant,T(n)isO(n+k2),.,O(n2)TheamortizedtimeofapushoperationisO(n)7ElementaryDataStructuresDirectAnalysisoftheDoublingStrategyWereplacethearrayk=log2ntimesThetotaltimeT(n)ofaseriesofnpushoperationsisproportionalton+1+2+4+8+…+2k=n+2k+1-1=2n-1T(n)isO(n)TheamortizedtimeofapushoperationisO(1)puterasacoin-operateddevicerequiring1cyber-

第02章基本数据结构stacksqueuesliststrees教学提纲 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数30
  • 收藏数0 收藏
  • 顶次数0
  • 上传人sunfuliang7807
  • 文件大小863 KB
  • 时间2019-12-11