数结构与算数据结构与算法

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

()()©wangzhao1zzz©wangzhao2zzzz©wangzhao3zzzzzz©wangzhao4zzkeyattribute{{Associationz()().().zz©wangzhao5zz{{{{zkeykey{{{{©wangzhao6zz{z{zzzz©wangzhao7zzASL(AverageSearchLength)(gg)∑=niicpASL{n∑=iiicpASL1{n{piipi=1/npi1/n{ciizzz©wangzhao8z{DictionarycreateEmptyDictionary(void){DictionarycreateEmptyDictionary(void)zdickeyp{intsearch(Dictionarydic,KeyTypekey,Positionp)z{intinsert(Dictionarydic,DicElementele)zkeyzkey{intdelete(Dictionarydic,KeyTypekey)©wangzhao9z:{({()©wangzhao10zzzzzz©wangzhao11zz©wangzhao12typedefintKeyType;tdfitDtTtypedefintDataType;typedefstruct{KeyTypekey;/**/DataTypevalue;/**/}DicElement;typedefstruct{intMAXNUM;intn;/*nMAXNUM*/;DicElement*element;}SeqDictionary;typedefstruct{intn;/**/}Seqcoy;*KeyTypeDataType{intn;//DicElementelement[MAXNUM];}SeqDictionary;©wangzhao13KeyTypeDataTypeintz{{{©wangzhao14-1-1zz{position{position{positionintseqSearch(SeqDictionary*pdic,KeyTypek,int*position)position)/*key*/{inti;{inti;for(i=0;ipdic-n;i++)/**/if(pdicelement[i]key==k)/**/if(pdic-element[i].key==k)/**/{*position=i;return(1);}*itidit(0)/**/*position=pdic-n;return(0);/**/}©wangzhao152-2intseqSearch(SeqDictionary*pdic,KeyTypek,)/*key*//*key*/{inti=pdic-n;pdic-element[0].key==k;/**/while(pdic-element[i].key!=k)while(pdicelement[i].key!k)i--;tireturni;}1n©wangzhao16zelement[0]c1=1zielement[i1]c=izielement[i-1]ci=iASL=1P+2P++nPASL=1P1+2P2+…+nPnzPi=1/n∑∑+===niniiinnicpASL112/)1(/z==ii11zkeynzASL=O(n)©wangzhao17()zP1≥P2…≥PnASL11©wangzhao18zznn©wangzhao19zz©wangzhao20z()-{{{z9key9keyyz©wangzhao21z051018252732415168739905,10,18,25,27,32,41,51,68,73,992578©wangzhao22z{lhih{lowhigh©wangzhao23zzz012345678910z0510182527324151687399z051018252732415168739952811392147103258113609258114©wangzhao2410714552828360910714©wangzhao25zASLsucc12*23*44*4/115=1+2*2+3*4+4*4/11=32836091071407©wangzhao26z2j-1jz2j12j+11z2j-1n=2j+1-1j+1z2jn+1=2j+1zjlog(n+1)=j+1zjlog2(n+1)=j+1zlog2(n+1)⎤zx⎤x©wangzhao27n2h1hl(n1)n=2h-1h=log2(n+1)h-1020112121212……k2kk+1k2k+1……h2hh+1h2h+1©wangzhao28∑=niicpASL)22(11−××=∑−hhih∑∑−=hiiiiip1121)122(1)(1+××=∑=hnhhi∑=×=iiin1112)1)1()1((1)122(+−××=hhn−++++×=jn122221(1L1)1)1()1((++−+××=nnhn−++++hh121222222L1))1((1+−+××=nnnhn−−++++hh112)222L11−×+=hnn∑∑−×=+hhm121)21)1(log12−++=nnn•nn100∑∑∑==hihiimn1112©wangzhao29:ASL≈log2(n+1)-1∑=−−×=iihn11)22(1z1000n=1000ASL=500ASL≈9z©wangzhao30O©wangzhao31zzzzzz©wangzhao32zd0d1key0key1d1zkey1key2d2zKeynKeyndn©wangzhao33zzzzz©wangzhao34(BlockingSearch)(BlockingSearch)zz……zzz©wangzhao35•224886171322121389203342443824486058744986532212138920334244382448605874498653©wangzhao36zzkeyzkey,zkey=38zkey=38zkey=15©wangzhao37ztypedefstructtypedefstruct{KeyTypemaxkey;/**/i1/**/intpos_1rec;/**/}IndexNode;/**/typedefstructtypedefstruct{IndexNodeidx_block[MAXNUM];/**/intnumblock;/**/intnum_block;/**/}*Pindex;©wangzhao38ASLbs=Lb+LwASLbsLbLwLbASLLwASLbSwSnbss=n/b1/b1/sASL©wangzhao39zASLnsASL=(b+1)/2+(s+1)/2=(n/s+s)/2+1sASL=(b+1)/2+(s+1)/2=(n/s+s)/2+1zASLASLns=1+nzn=1000ASL≈32ASL≈50031≈=nsASL500ASL≈9©wangzhao40•ASL=log2(n/s+1)-1+(s+1)/2≈log(n/s+1)+s/2≈log2(n/s+1)+s/2•©wangzhao41zzzz©wangzhao42zzz©wangzhao43z{{zinvertedindexzz.z.z:©wangzhao4411012009.11.622052009.11.730852009.11.1240402009.11.1250872009.11.2560982009.11.2571062009112571062009.11.2582012009.11.301,52009.11.61200911721,52672,6,73482009.11.722009.11.123,420091125672,6,73484,82009.11.255,6,72009.11.3084,8©wangzhao45zz©wangzhao46A10110212009.11.6B20510142009117B20510142009.11.7C08511062009.11.12D04011082009.11.12E08712032009.11.25F09821052009.11.25G10610122009.11.25H20101092009.11.302009.11.6A1A22009.11.7B12009.11.12C220091125E3B3C1©wangzhao472009.11.25E32009.11.30H1D2zzzzzz©wangzhao48zzzz©wangzhao49z{Hash{keykeyhh(key)h(key)h(key)z(hashing)z©wangzhao5011z30...zC[30]C[i]ii.h(key)=key.©wangzhao5122zBEIJING2BEIJING230303030keyBEIJINTIANJIHEBEISHAXSHANSHANHENASICHUkeyBEIJINGTIANJINHEBEISHAXNXISHANGHAISHANDONGHENANSICHUANh1(key)0220081919190819h2(key)0904172828262203©wangzhao52(y)0904172828262203zzkey1key2hh(key1)=h(key2)(y)(y)z().()zh(key).zz=)(α©wangzhao53z1αzHash©wangzhao54zzzz©wangzhao55zzz{{©wangzhao56zzzzzzz©wangzhao57z{h(key)=a*key+bab{1~100010203...252627...100010203...252627...100123...252627...1003000200050001050300020005000...1050............010203...221949195019511970©wangzhao58194919501951...197015000zzzzzzz©wangzhao59z¾(395003,395010,395012,395085,395097)0310128597zz©wangzhao60zzzzzzz©wangzhao61z¾key=4731key2=223823613¾key=4731key2=223823613382h(4731)=382zzz©wangzhao62zzzzzzz©wangzhao63zzkey=05824222414©wangzhao64zzzzzzz©wangzhao65zzkey=(236075)1013(236075)13zkey(236075)10,13(236075)13,104(236075)13=2*135+3*134+6*133+7*131+5=(841547)10(236075)13213+313+613+713+5(841547)102~5h(236075)=4154©wangzhao66zzzzzzz©wangzhao67zh(key)=key%p{{pm{m=81632641282565121024p=71331611272515031019{p©wangzhao68zz©wangzhao69zzzz©wangzhao70zzz©wangzhao71zzzz{{{©wangzhao72z{{d(d=h(key))d+1,d+2,…,m-1,0,1,…,d-1(md,d,…,,0,,…,d()key{ddd©wangzhao73¾K={1873100568992741513225}}elementm(m=13)h(key)=key%13d=key%13h(18)=5,h(73)=8,h(10)=10

1 / 86
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功