- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
数据结构_查找2
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 45 bt 90 24 3 37 61 70 100 Delete 37 b e c d g h a After deleting 37 45 90 bt 100 3 24 61 70 c g h e HASHING All search algorithms so far Rely on comparison operations Performance O(n) or O( log n) Assume a function that maps a key to an integer f ( key ) ? integer The operations (insert ,search) : O(1). Hash Tables The most simplest implementation of a hash table is using an fixed size array. In a hash table, a hash function is used to map keys into the positions in the table. This action is called hashing The ideal hashing case: if a record p has a key k and f is the hash function, then p is stored in position f(k) of the table (index: 0..m-1) . Hash function - Address Calculator Hash Function Hash Table m-1 {Zhao, Qian, Sun, Li, Wu, Chen, Han, Ye, Dei} Example:there are 9 keys Hash function f(key) =?(Ord(first char) -Ord(A)+1)/2? Zhao Chen Qian Sun Li Wu Han Ye Dei Problem: insert key Zhou , what will happen? Hashing- General Idea When an record needs to be inserted into the Hash Table: The record is stored in the array at an index value got by a Hash function. If more than one key (items) are mapped into the same index value, then we say that we have a collision. key1? key2,but f(key1) = f(key2). It is hard to avoid collisions totally. Hash Functions It is impossible to find a hash function which can totally avoid collisions. So f needs to have the following properties. ? f ( x ) must be easy to compute and minimizes the number of collisions. ? f ( x ) should be unbiased. That is, for any x and any i, we have that Probability( f ( x ) = i ) = 1 / m. Such kind of a hash function is called a uniform hash function. Hash Functions – Modulo Modulo operator provides a simple and effective hash function. We will use modulo as our hash function in the rest of our discussions. h(x) = x mod m (m is the tableSize) The table size should be a prime: 7,11,
文档评论(0)