ImageVerifierCode 换一换
格式:PPT , 页数:86 ,大小:632.04KB ,
资源ID:12509693      下载积分:5 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/12509693.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(程序设计与算法基础3优秀文档.ppt)为本站上传会员【二***】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

程序设计与算法基础3优秀文档.ppt

1、Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,程序设计与算法基础(6),潘爱民,2006/10/30,Outline,Hash tables,Bloom filter,Inverted index,Searching problem again,For a linked list,-O(,n,),For a sorted array,-O(log,n,),Can we expect O(1)?which m

2、eans,Regardless of the number of elements being searched,the run time is always the same,Given a key,the position in the table can be accessed directly,Operations on hash tables,Collection of pairs,(,key,element,),here,key,maybe a string,number,record,etc.,Pairs have different keys,Operations,Get(th

3、eKey),Delete(theKey),Insert(theKey,theElement),Ideal Hashing,Uses a 1D array(or table),table,0,m,-1.,Each position of this array is a,bucket,A bucket can normally hold only one pair,Uses a hash function,h,that converts each key,k,into an index in the range 0,m,-1,h,(,k,)is the home bucket for key,k,

4、Every pair(,key,element,)is stored in its home bucket,table,h,key,0,1,2,3,4,5,6,7,Ideal Hashing Example,Pairs are:,(22,a),(33,c),(3,d),(73,e),(85,f),Hash table is,table,07,m,=8,Hash function is,h,(,key,)=,key,/11,Pairs are stored in table as below,(85,f),(22,a),(33,c),(3,d),(73,e),Get,Insert,and,Del

5、ete,take,O(1),time,What Can Go Wrong?,Where does,(26,g),go?,Keys that have the same home bucket are synonyms,22,and,26,are synonyms with respect to the hash function that is in use.,The home bucket for,(26,g),is already occupied.,0,1,2,3,4,5,6,7,(85,f),(22,a),(33,c),(3,d),(73,e),What Can Go Wrong?,A

6、collision,occurs when the home bucket for a new pair is occupied by a pair with a different key,An,overflow,occurs when there is no space in the home bucket for the new pair,When a bucket can hold only one pair,collisions and overflows occur together,Need a method to handle overflows,(85,f),(22,a),

7、33,c),(3,d),(73,e),Hash Table Issues,Choice of hash functions,Collision resolution,Size of hash table,The size of bucket&number of buckets,Hash functions,Definition:,A hash function transforms a key,K,into an index in the table used for storing items of the same type as,K,If hash function,h,transfo

8、rms different keys into different numbers,it is called a,perfect hash function,Therefore,a hash function is a mapping from,n,items to,m,positions,Total number of possible mappings is,m,n,If,n,m,the number of perfect hash functions is,m!/(m-n)!,Hash Functions,Two parts,Convert a key into an integer i

9、n case the key is not an integer,h,(,k,),Map an integer into a home bucket,f,(,k,),is an integer in the range,0,m,-1,where,m,is the number of buckets in the table,String To Non-negative Integer,Each character is,1 byte,long,An int is,4 bytes,A two-character string,s,may be converted into a unique 4

10、byte non-negative int using the code:,int answer=s.at(0);,answer=(answer 8)+s.at(1);,Strings that are longer than 3 characters do not have a unique non-negative int representation,String To Nonnegative Integer,unsigned long operator()(const string theKey),/Convert theKey to a nonnegative integer.,un

11、signed long hashValue=0;,int length=(int)theKey.length();,for(int i=0;i length;i+),hashValue=5*hashValue,+theKey.at(i);,return hashValue;,Map into a home bucket,Most common method is by division,homeBucket,=h(,theKey,)%,divisor,;,divisor,equals the number of buckets,m,0,homeBucket,this key is not in

12、 the DI,try(word,n,m);,A change of any bit in the input will cause the change of any bit in the output with 0.,PageRank was developed at Stanford University by Larry Page and Sergey Brin for a search engine-Google,Information needed,Urania U=4 h=1012345678,Never overflow if the capacity of the linea

13、r list is unlimited,The probability of false positive decreases as m increases,Combine linear probing and chaining,k too small=probability of different keys having same signature is high.,Open addressing,put word at the beginning of wordList and detach its hash value;,Terpsichore T=0 h=22578,Build i

14、nverted indexes,Urania U=4 h=1012345678,Urania U=2 h=8*02345678,not reserved),Uniform Hash Function,Equivalently,the probability that a randomly selected key has bucket,i,as its home bucket is,1/,m,0,i,m,A uniform hash function minimizes the likelihood of an overflow when keys are selected at random

15、0,1,2,3,4,5,6,7,(85,f),(22,a),(33,c),(3,d),(73,e),Hashing By Division,keySpace,=,all,int,s,For every,m,the number of,int,s that get mapped(hashed)into bucket,i,is approximately,2,32,/,m,Therefore,the division method results in a uniform hash function when,keySpace,=,all,int,s,In practice,keys tend

16、to be correlated,So,the choice of the divisor,m,affects the distribution of home buckets,Selecting The Divisor,Because of this correlation,applications tend to have a bias towards keys that map into odd integers(or into even ones),When the divisor is an even number,odd integers hash into odd home bu

17、ckets and even integers into even home buckets,20%14=6,30%14=2,8%14=8,15%14=1,3%14=3,23%14=9,The bias in the keys results in a bias toward either the odd or even home buckets,Selecting The Divisor,When the divisor is an odd number,odd(even)integers may hash into any home,20%15=5,30%15=0,8%15=8,15%15

18、0,3%15=3,23%15=8,The bias in the keys does not result in a bias toward either the odd or even home buckets,Better chance of uniformly distributed home buckets,So do not use an even divisor,Selecting The Divisor,Similar biased distribution of home buckets is seen,in practice,when the divisor is a mu

19、ltiple of prime numbers such as,3,5,7,The effect of each prime divisor,p,of,m,decreases as,p,gets larger,Ideally,choose,m,so that it is a prime number,Alternatively,choose,m,so that it has no prime factor smaller than,20,Hashing by folding,The key is divided into several parts,and these parts are co

20、mbined or folded together,Shift folding,Using a simple operation such as addition to combine them in a certain way,For example,the social security number(SSN),123-45-6789,(123+456+789)%,m,(,m=1000,),Boundary folding,The pieces of the keys are folded on the borders between different parts,for example

21、123+654+789)%,m,(,m=1000,),About folding,Simple and fast,bit pattern can be used instead of numerical values,In the case of strings,Xoring the characters together,and using the result for the address,Xoring the chunks of strings rather than single characters.The length of a chunk is equal to the n

22、umber of bytes in an integer,Typically,the result of folding processing are divided modulo,m,Hashing by a Mid-square function,The key is,squared,and the middle or,mid,part of the result is used as the hash value,Entire key participates in generating the hash value,so a better chance that the differe

23、nt values are generated for different keys,In practice,it is more efficient to choose a power of 2 for the size of the table,m,and extract the mid part of the bit representation of the square of a key,just using a mask and a shift operation,For example,31212=10010100,101000010,1100001,the mid part,1

24、01000010,=322,Hashing by extraction,Only a part of the key is used to compute the address,If the part is distributed uniformly,it can be sufficient for hashing(provided the omitted portion distinguishes the keys only in an insignificant way),For example,in the student ID,some digits are safely omitt

25、ed in a hash function,ISBN code is similar,Hashing by radix transformation,The key is transformed into another number base,For example,K,is the decimal number,345,then its value in base,9,is,423,(9),Then it is divided modulo,m,in original base,the resulting number is used as the hash value,If,m,=100

26、345,(10),and,245,(10),are not hashed to the same value,but,345,(10),and,264,(10),will be hashed to a same value,23,Hashing by cryptographic hash algorithms,Strong hash algorithms,A change of any bit in the input will cause the change of any bit in the output with 0.5 probability approximately,The e

27、ncryption algorithm has similar feature,Using cryptographic algorithms to hash a key,For example,compute the,MD5(,key,),or,SHA1(,key,),or encrypt the key with a fixed encryption key,DES,k,(,key,),Then divided modulo,m,Collision resolution,Avoid collision,Increasing the table size may lead to better

28、hashing,but sometimes not,The two factors hash function and table size may minimize the number of collisions,but they can not completely eliminate them(if the size of key space is larger than the table size),Some strategies,Open addressing,Chaining,Bucket addressing,Collision resolution by opening a

29、ddressing,A collision occurs when the home bucket for a new pair,(key,element),is occupied,We may handle collisions by:,Search the hash table in some systematic fashion for a bucket that is not occupied.,Linear probing,Quadratic probing,Random probing,Eliminate overflows by permitting each bucket to

30、 keep a list of all pairs for which it is the home bucket,Dynamic array,linked list,Opening addressing,If the position h(K)is occupied,then the positions in the probing sequence,norm(h(K)+p(1),norm(h(K)+p(2),norm(h(K)+p(m),are tried until,either an available cell is found,or the same positions are t

31、ried repeatedly,or the table is full,In the probing sequence,Function,p,is,probing function,i,is a,probe,norm,is a normalization function,(division modulo to the size of the table),Linear probing,In the open addressing,p(i),=,c,*,i,so if,c,=1,then the position to be tried is,(h(K)+i),In linear probi

32、ng,Insertion,:the position to store a key is found by sequentially searching all positions starting from the position calculated by the hash function until an empty cell is found,Tendency to create clusters in the table,the empty cells following clusters have a much greater chance to be filled than

33、other positions,Linear Probing Get And Insert,divisor=,m,(number of buckets),=17,Home bucket=key%17,0,4,8,12,16,Insert pairs whose keys are,6,12,34,29,28,11,23,7,0,33,30,45,6,12,29,34,28,11,23,7,0,33,30,45,Quadratic probing,In the open addressing,In general,p(i)=c,2,*i,2,+c,1,*i,for example,p(i),=(-

34、1),i,-1,(,i+,1)/2),2,so the position to be tried is,h(K),h(K)+1,h(K)-1,h(K)+4,h(K)-4,h(K)+(m-1),2,/4,h(K)(m-1),2,/4,The experience value of,m,(table size)is a prime in the form of 4,j,+1,Question:,Why not use,p,(,i,)=,i,2,0,i,m,5/4*1000=1250,.,Pick,m,(equal to,divisor,)to be a prime number or an odd

35、 number with no prime divisors smaller than,20,Collision resolution:chaining,Each bucket keeps a linear list of all pairs for which it is the home bucket,Never overflow if the capacity of the linear list is unlimited,The linear list may or may not be sorted by key.,The linear list may be an array li

36、near list or a chain,Performance,Increasing the length of the lists can degrade retrieval performance,Require additional space for pointers,Put in pairs whose keys are,6,12,34,29,28,11,23,7,0,33,30,45,Home bucket,=key%17,.,Sorted Chains,0,4,8,12,16,12,6,34,29,28,11,23,7,0,33,30,45,Expected Performan

37、ce,Note that,LF,0,.,Expected chain length is,LF,.,S,n,1+LF/2,(in the case of unsorted list),U,n,LF,Coalesced hashing(coalesced chaining),Combine linear probing and chaining,h,(,K,)=,K,%17,Insert pairs whose keys are,6,12,34,29,28,11,23,7,0,Alternatively,the colliding key can be put in an overflow ar

38、ea(called a cellar),0,4,8,12,16,6,12,29,34,28,11,23,7,0,Bucket addressing,Associate a,bucket,with each address,and a bucket is a block of space enough to store multiple items,Collision is not totally avoided,if a bucket is full,then,A new item hashed to the bucket can be stored in the next bucket,ju

39、st as does in the open addressing approach,The new item can also be stored in an overflow area.The bucket will be marked with a flag indicating it has additional items to be searched,Perfect hash functions,Perfect hash functions,or,ideal hash functions,It hashes a key to its proper position,and,no c

40、ollisions occur,An assumption is that the key set is known,If the number of cells in the table is equal to the number of data items,it is called a,minimal perfect hash function,so no space is wasted,Examples,Reserved words used by assemblers,compilers,files on unerasable optical disks,dictionaries,I

41、t is not easy to obtain a perfect hash function,Cichellis method to construct a minimal perfect hash function,Developed by Richard J.Cichelli,Used to hash a relatively small number of reserved words,The function is of the form,h,(,word,)=(,length,(,word,)+,g,(,firstletter,(,word,)+,g,(,lastletter,(,

42、word,)mod,m,where,g,is the function to be constructed,reserve h(word);,Search cluster for pair(if any)to fill vacated bucket,The new item can also be stored in an overflow area.,These lists can be used to solve Boolean queries:,The key is divided into several parts,and these parts are combined or fo

43、lded together,(key,element),here key maybe a string,number,record,etc.,Pick m(equal to divisor)to be a prime number or an odd number with no prime divisors smaller than 20,Mapping(dependency graph):between h1 to h2 for each word,Bucket addressing,k=2(2 hash functions),Bloom in 1970,Insert pairs whos

44、e keys are 6,12,34,29,28,11,23,7,0,Hash function is h(key)=key/11,Cichellis algorithm,Choose a value for Max,Compute the number of occurrences of each first and last letter in the set of all words,Order all words in accordance to the frequency of occurrence of the first and the last letters,Examples

45、C,alliop,e,C,li,o,E,rat,o,E,uterp,e,M,elpomen,e,P,olyhymni,a,T,erpsichor,e,T,hali,a,U,rani,a,=,E(6),A(3),C(2),O(2),T(2),M(1),P(1),U(1),Euterpe,Calliope,Erato,Terpsichore,Melpomene,Thalia,Clio,Polyhymnia,Urania,Cichellis algorithm(cont.),Search(,wordList,),if,wordList,is empty,halt;,word,=first wor

46、d from wordList;,wordList,=wordList with the first word detached;,if the first and the last letters of word are assigned g-values,try(,word,-1,-1)/-1 signifies value already assigned,if success,Search(,wordList,),put,word,at the beginning of,wordList,and detach its hash value;,else if neigher the fi

47、rst nor the last letters has a g-value,for each,n,m,in 0,Max),try(,word,n,m,);,if success,Search(,wordList,),put,word,at the beginning of,wordList,and detach its hash value;,else if either the first or the last letter has a g-value,for each,n,in 0,Max),try(,word,-1,n,);,if success,Search(,wordList,)

48、put,word,at the beginning of,wordList,and detach its hash value;,Cichellis algorithm(cont.),try(word,firstLetterValue,lastLetterValue),if,h,(,word,)has not been claimed,reserve h(word);,if,not,-1(i.e.,not reserved),assign firstLetterValue and/or lastLetterValue as g-values of,firstletter(word)and/o

49、r lastletter(word),return,success,return,failure,A invocations of the searching procedure,reserved hash values,Euterpe E=0 h=77,Calliope C=0 h=878,Erato O=0 h=5578,Terpsichore T=0 h=22578,MelpomeneM=0h=002578,Thalia A=0 h=6025678,Clio h=40245678,PolyhymniaP=0h=101245678,Urania U=0 h=6*01245678,Urani

50、a U=1 h=7*01245678,Urania U=2 h=8*01245678,Urania U=3 h=0*01245678,Urania U=4 h=1*01245678,PolyhymniaP=1h=2*0245678,PolyhymniaP=2h=3 02345678,Urania U=0 h=6*02345678,Urania U=1 h=7*02345678,Urania U=2 h=8*02345678,Urania U=3 h=0*02345678,Urania U=4 h=1012345678,About cichellis algorithm,A brute-forc

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服