`
leonzhx
  • 浏览: 785981 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多

1.  Definition : the load factor of a hash table is (# of objects in hash table/ # of buckets of hash table)

     -- load factor = O(1) is necessary condition for operations to run in constant time.

     -- with open addressing, need << 1.

     -- good Hash Table performance need to control load.

 

2.  For good HT performance, need a good hash function.

     Ideal : user super-clever hash function guaranteed to spread every data set out evenly.

     Problem : DOES NOT EXIST! (for every hash function, there is a Pathological Data Sets

     Reason : fix a hash function h : U -> {0,1,2,…,n-1} , there exist bucket i such that at least

     |u|/n elements of U hash to i under h.  if data set drawn only from these, everything collides !

 

 

3.  Solutions to pathological data sets

    1) Use a cryptographic hash function (e.g. SHA-2)

        -- infeasible to reverse engineer a pathological data set

    2) Use randomization. 

        -- design a family H of hash functions such that for all data sets S, “almost all” functions spread S

out “pretty evenly”.

 

4.  Universal Hash Functions Definition :

    -- Let H be a set of hash functions from U to {0,1,2,…,n-1} 

    -- H is universal if and only if : for all x,y in U (with x ≠ y ) , P(h in H) { x , y  collide} <= 1/n

        (n = # of buckets) When h is chosen uniformly at random from H.

   (i.e., collision probability as small as with “gold standard” of perfectly random hashing)

 

5.  Example: Hashing IP Addresses

     Let U = IP addresses of the form (x1,x2,x3,x4), with each xi in [0, ... , 255]

     Let n = a prime (e.g., small multiple of # of objects in HT)

     Definition : Define one hash function ha per 4-tuple a = (a1,a2,a3,a4) with each ai in [0, ..., n-1]

                       Define ha : IP addrs --> buckets by :

                                    ha ( x1, x2, x3, x4) = (a1x1 + a2x2 + a3x3 + a4x4) mod n

                       Define H = { ha| a1, a2, a3, a4 in [0, ..., n] }

      Proof : Consider distinct IP addresses (x1,x2,x3,x4), (y1,y2,y3,y4). Assume x4 ≠ y4

      collision <==> a1x1 + a2x2 + a3x3 + a4x4 = a1y1 + a2y2 + a3y3 + a4y4 ( mod n)

                    <==> a4(x4-y4) = a1(y1-x1) + a2(y2-x2) + a3 (y3-x3) (mod n)

      condition probability on random choice of a1, a2, a3.  (a4 is still random)

      x4 ≠ y4 (x4-y4 ≠ 0 mod n , assume n is bigger than any xi) n is prime, a4 uniform at random

 

6.  Chaining: Constant-Time Guarantee

     Claim : All operations run in O(1) time when hash table is implemented with chaining. Hash function h

chosen uniformly at random from universal family H.

     Caveats: 1) in expectation over the random choice of the hash function h. 

                     2) assumes |S| = O(n)  (load factor is |S|/n = O(1) )

                     3) assumes takes O(1) time to evaluate hash function

     Proof: analyze an unsuccessful Lookup (other operations only faster).

     Let S = data set with |S| = O(n) Consider Lookup for x not in S :

     Running Time : O(1) (compute h(x) ) + O(list length in A[h(x)] ) (traverse list , call it L)

     For y in S (so, y ≠ x) define Zy = 1 if h(y) = h(x) , 0 otherwise. So L = Sum(y in S) { Zy}

     So E[L] = E(Sum(y in S) {Zy}) = Sum (y in S) { E(Zy)} <= |S|/n = load factor = O(1)

 

7.  Open Addresing Performance :

    Heuristic assumption : (for a quick & dirty idealized analysis only) all n! probe sequences equally.

    under heuristic assumption, expected Insertion time is ~ 1/(1-load)

    Proof : A random probe finds an empty slot with 1- load 

               Insertion time ~ the number N of coin flips to get “heads”, where Pr[“heads”] = 1 - load

               E[N] = 1 (1st flip) + load (probability of tail) * E[N]

               So E[N] = 1/ (1-load)

     With linear probing, heuristic assumtion is completely false. 

      Assume instead : initial probes uniform at random independent for different keys ( less false)

      Theorem : [Knuth 1962] under above assumption, expected Insertion time is 1/(1-load)^2

 

分享到:
评论

相关推荐

    universal hashing.pdf

    1998年的英文资料,共12页,非常详细地介绍了universal hashing。universal hashing(在随机算法或数据结构中)是指从具有一定数学属性的哈希函数族中随机选择哈希函数。 即使数据是由对手选择的,这也保证了预期的...

    java-Hash算法大全.doc

    七、Universal 哈希(Universal Hash) Universal 哈希是一种使用查找表来生成哈希值的哈希算法,该算法可以生成均匀分布的哈希值。该算法的实现代码如下: ```java public static int universal(char[] key, int ...

    数据结构常用算法c++实现

    Universal hash function Perfect hash Java's string hash FNV-1a string hash SimHash Bloom Filter SHA-1 Message Digest Algorithm MD5 Base64 Graph data structure Strongly Connected Components(SCC) Prim'...

    MIT 麻省理工 算法课程-第八节-讲义(经典!)

    ##### Constructing a Set of Universal Hash Functions - **构造方法**:构造一个通用哈希函数集的关键在于找到一种方式,使得任何两个不同的键值通过该集合中的哈希函数映射后发生冲突的概率足够低。 - **示例**...

    hash算法大全.doc

    Universal Hashing 是一种通用的 Hash 算法,它可以用于各种类型的数据。Universal Hashing 算法的实现代码如下: ```java public static int universal(String key) { // 实现 Universal Hashing 算法的代码 } ```...

    基于应变和应力的Vumat子程序_hashin失效准则_动态应变_拉伸失效_hashin_vumat

    在复合材料领域,模拟材料失效是一项关键任务,而Vumat(Variable-Material-Property Universal Material Subroutine)子程序是Abaqus等有限元软件中实现这一功能的重要工具。标题中的"基于应变和应力的Vumat子程序_...

    Sarah Adel Bargal_Universal Hashing notes.pdf

    比较新的英文资料,共4页,非常简洁地介绍了universal hashing,非常容易理解。 universal hashing(在随机算法或数据结构中)是指从具有一定数学属性的哈希函数族中随机选择哈希函数。 即使数据是由对手选择的,这...

    Hash算法大全(java实现)参照.pdf

    Hash算法是一种将任意长度的数据映射为固定长度的哈希值的算法,通常用于数据校验、快速查找、简化数据存储等场景。在Java中,实现Hash算法有多种方法,这里我们将探讨几种常见的Hash算法及其Java实现。 1. **加法...

    Hash算法大全(java实现)汇编.pdf

    Universal Hashing是一种设计原则,旨在确保对于任何两个不同的输入,Hash函数产生不同结果的概率至少为1/2。它通常需要一个随机生成的哈希表和掩码来确保更好的哈希质量。这种方法在需要避免特定碰撞的场景中很...

    相关键几乎通用的哈希函数:定义,构造和应用

    本文提出了相关键几乎通用哈希函数(Related-Key Almost Universal Hash Functions),这是一种在相关键攻击场景下对几乎通用哈希函数的自然扩展,并对其定义、构造和应用进行了详细探讨。 首先,文章介绍了通用...

    Universal and Perfect Hashing (lect1004)-计算机科学

    Lecture 10Universal and Perfect Hashing10.1 ...known as universal hash function families) and perfect hashing.Material covered in this lecture includes:• The formal setting and general idea of h

    Universal Hashing全域哈希原理与python实现,减少hash冲突/碰撞!

    全域哈希原理与实现1-hash哈希介绍2-Universal hashing全域哈希法3-构造一个全域哈希H\mathcal{H}H4-python实现 1-hash哈希介绍 hash函数y=h(k)y=h(k)y=h(k),把任意长度的输入kkk通过散列算法hhh变换成固定长度的...

    基于SQL的加密数据库模糊查询机制

    同时,本文还提出了一种新的支持直接在加密数据上进行查询的SQL模糊查询机制,它是通过FPE和通用哈希函数(Universal Hash Function,UHF)构建的。本文还对所提出的机制的安全性进行了分析,并通过广泛的实验来展示...

    一个关于MAC伪随机性与不可伪造性的注记 (2010年)

    Wegman-Carter MAC是一种基于通用哈希函数(Universal Hash Function, UHF)的MAC,它的安全性基于UHF的性质。虽然Wegman-Carter MAC也是伪随机的,但在某些情况下可能并不具备不可伪造性。 ##### 2. 随机MAC与带...

    COONY_HASH_SMP_NEW

    COONY_HASH_SMP_NEW 是一个专为中象游戏设计的免费引擎,它采用了UCCI(Universal Chess Interface)协议,使得该引擎可以与各种国际象棋用户界面无缝对接。此项目的核心亮点在于其对多核心处理器的支持,尤其是8...

    Regular and Almost Universal Hashing - An Efficient Implementation - 2016 (1609.09840)-计算机科学

    Regular and almost universal hashing: an ... Many existing families of hash functions are universal: given two data objects, the probability that they have the same hash value is low given that w

    Faster 64-bit Universal Hashing using Carry-less Multiplication - 2015 (1503.03465)-计算机科学

    use CLMUL to implement an almost universal 64-bit hash family (CLHASH). We compare this new family with what might be the fastest almost universal family on x64 proces- sors (VHASH). We find that ...

    UMAC Message Authentication Code using Universal Hashing

    UMAC(Universal Message Authentication Code)是一种使用通用散列函数的消息认证码算法,它的设计目标是在单处理器的现代计算机上以非常快的速度进行计算,它能够达到每字节一个周期的测量速度。UMAC的核心依赖于...

    数据结构Advanced-Data-Structures

    Universal hashing 496 Linear hashing 501 Extendible hashing 502 2-choice hashing 508 Pearson hashing 508 Fowler–Noll–Vo hash function 509 Bitstate hashing 511 Bloom filter 512 Locality preserving ...

Global site tag (gtag.js) - Google Analytics