SlideShare uma empresa Scribd logo
1 de 28
Hashing
   Hash functions
     Hash-code maps
     Compression maps

   Open addressing
     LinearProbing
     Double hashing
Hash Functions
 Need     to choose a good hash function
   quick  to compute
   distributes keys uniformly throughout the table
   good hash functions are very rare – birthday
    paradox
 How   to deal with hashing non-integer keys:
   find   some way of turning keys into integers
      eg. remove hyphen in 9635-8904 to get 96358904!
      for a string, add up ASCII values of the characters of
       your string (e.g., java.lang.String.hashCode())
   then   use standard hash function on the integers
From Keys to Indices
 The mapping of keys to indices of a hash table
  is called a hash function
 A hash function is usually the composition of
  two maps, a hash code map and a
  compression map.
    An essential requirement of the hash function
     is to map equal keys to equal indices
    A “good” hash function minimizes the
     probability of collisions
Popular Hash-Code Maps
 Integer  cast: for numeric types with 32 bits or
  less, we can reinterpret the bits of the
  number as an int
 Component sum: for numeric types with
  more than 32 bits (e.g., long and double), we
  can add the 32-bit components.
 Why is the component-sum hash code bad
  for strings?
Hash-Code Maps (2)
 Polynomial accumulation: for strings of a natural
  language, combine the character values (ASCII
  or Unicode) a0a1 ... an-1 by viewing them as the
  coefficients of a polynomial:
      a0 + a1x + ...+ xn-1an-1
 The polynomial is computed with Horner’s rule,
  ignoring overflows, at a fixed value x:
      a0 + x (a1 +x (a2+ ... x (an-2+ x an-1) ... ))
 The choice x = 33, 37, 39, or 41 gives at most 6
  collisions on a vocabulary of 50,000 English
  words
Compression Maps
 Use the remainder
   h(k) = k mod m, k is the key, m the size of the
    table
 Need to choose m
 m = be (bad)
   if m is a power of 2, h(k) gives the e least
    significant bits of k
   all keys with the same ending go to the same
    place
 m prime (good)
   helps ensure uniform distribution
   primes not too close to exact powers of 2
Compression Maps (2)
 Example
   hash table for n = 2000 character strings
   we don’t mind examining 3 elements
   m = 701
     a prime near 2000/3
     but not near any power of 2
Compression Maps (3)
  Use
    h(k)  = m (k A mod 1)
    k is the key, m the size of the table, and A
     is a constant
     0<A<1
  The   steps involved
    map  0...kmax into 0...kmax A
    take the fractional part (mod 1)
    map it into 0...m-1
Compression Maps (4)

Choice of m and A
 value of m is not critical, typically use m =
  2p
 optimal choice of A depends on the
  characteristics of the data
                         5 1
 Knuth says use     A
                          2  (conjugate of the
  golden ratio) – Fibonacci hashing
Compression Maps (5)
Multiply, Add, and Divide (MAD):
h(k) = |ak + b| mod N
 eliminates patterns provided a is not a
  multiple of N
 same formula used in linear congruential
  (pseudo) random number generators
Universal Hashing
   For any choice of hash function, there exists a
    bad set of identifiers
   A malicious adversary could choose keys to be
    hashed such that all go into the same slot
    (bucket)
   Average retrieval time is (n)
   Solution
    a  random hash function
     choose hash function independently of keys!
     create a set of hash functions H, from which h can
      be randomly selected
Universal Hashing (2)
   A collection H of hash functions is
    universal if for any randomly chosen f
    from H (and two keys k and l),
      Pr{f(k) = f(l)} 1/m
More on Collisions
 A key is mapped to an already occupied
 table location
   what   to do?!?
 Use a collision handling technique
 We’ve seen Chaining
 Can also use Open Addressing
   Probing
   Double    Hashing
Open Addressing
 Allelements are stored in the hash table
  (can fill up!), i.e., n m
 Each table entry contains either an element
  or null
 When searching for an element,
  systematically probe table slots
Open Addressing (2)
 Modify
      hash function to take the probe
 number i as the second parameter
                           h :U    0,1,..., m 1     0,1,..., m 1

 Hash function, h, determines the
  sequence of slots examined for a given
  key
 Probe sequence for a given key k given by
h(k ,0), h(k ,1),..., h(k , m 1) - a permutation of 0,1,..., m 1
Linear Probing
   If the current location is used, try the next table
    location
                   LinearProbingInsert(k)
                   if (table is full) error
                   probe = h(k)
                   while (table[probe] occupied)
                          probe = (probe+1) mod m
                   table[probe] = k

 Uses less memory than chaining as one does not
  have to store all those links
 Slower than chaining since one might have to
  walk along the table for a long time
Linear Probing Example
 h(k)= k mod 13
 insert keys: 18 41 22 44 59 32 31 73




                  31
                           73
                  44 32
           41     18 44 59 32 22 31 73
Lookup in linear probing
             41           18 44 59 32 22 31 73
     0   1   2    3   4   5   6   7   8   9   10   11   12

   To search for a key k we go to (k mod 13) and
    continue looking at successive locations till we
    find k or encounter an empty location.
   Successful search: To search for 31 we go to (31
    mod 13) = 5 and continue onto 6,7,8… till we
    find 31 at location 10
   Unsuccessful search: To search for 33 we go to
    (33 mod 5 = 7) and continue till we encounter an
    empty location (12)
Deletion in Linear Probing
            41           18 44 59 32 22 31 73
    0   1   2    3   4   5   6   7   8   9   10   11   12


 To delete key 32 we first search for 32.
 32 is found in location 8. Suppose we set this
  location to null.
 Now if we search for 31 we will encounter a null
  location before seeing 31.
 Lookup procedure would declare that 31 is not
  present.
Deletion (2)
            41           18 44 59 X 22 31 73
    0   1   2    3   4   5   6   7   8   9   10   11   12
   Instead of setting location 8 to null place a
    tombstone (a marker) there.
   When lookup encounters a tombstone it ignores
    it and continues with next location.
   If Insert comes across a tombstone it puts the
    element at that location and removes the
    tombstone.
   Too many tombstones degrades lookup
    performance.
   Rehash if there are too many tombstones.
Double Hashing
Uses two hash functions, h1, h2
 h1(k) is the position in the table where we first
  check for key k
 h2(k) determines the offset we use when searching
  for k
 In linear probing h2(k) is always 1.

  DoubleHashingInsert(k)
  if (table is full) error
  probe = h1(k); offset = h2(k)
  while (table[probe] occupied)
      probe = (probe+offset) mod m
  table[probe] = k
Double Hashing(2)

 If m is prime, we will eventually examine
  every position in the table
 Many of the same (dis)advantages as
  linear probing
 Distributes keys more uniformly than linear
  probing
Double Hashing Example
 h1(k) = k mod 13
 h2(k) = 8 – (k mod 8)
 insert keys: 18 41 22 44 59 32 31 73


                18 41 22 44 59 32 31 73




    0   1   2    3   4   5   6   7   8   9   10   11   12
Analysis of Double Hashing
 The  load factor is less than
 We assume that every probe looks at a
  random location in the table.
 1-   fraction of the table is empty.
 Expected number of probes required to
  find an empty location (unsuccessful
  search) is 1/(1- )
Analysis (2)
 Average    no of probes for a successful
  search = average no of probes required to
  insert all the elements.
 To insert an element we need to find an
  empty location.
   inserting   Avg no of probes   Total no of probes
   First m/2        <= 2                  m
   Next m/4         <= 4                  m
   Next m/8         <= 8                  m
Analysis(3)
 No of probes required to insert
  m/2+m/4+m/8+…+m/2i elements = number of
  probes required to leave 2-i fraction of the table
  empty = m x i.
 No of probes required to leave 1-     fraction of
  the table empty = - m log (1- )
 Average no. of probes required to insert n
  elements is - (m/n) log (1- ) = -(1/ ) log (1- )
Expected Number of Probes
   Load factor < 1 for probing
   Analysis of probing uses uniform hashing
    assumption – any permutation is equally likely
     What   about linear probing and double hashing?


                     unsuccessful      successful
         chaining
                         O(1       )    O(1      )
         probing               1          1  1
                        O               O ln
                            1 α          α 1 α
Expected Number of Probes (2)

Mais conteúdo relacionado

Mais procurados (20)

Lec3
Lec3Lec3
Lec3
 
Lec11
Lec11Lec11
Lec11
 
Lec1
Lec1Lec1
Lec1
 
Lec3
Lec3Lec3
Lec3
 
Lec5
Lec5Lec5
Lec5
 
Lec20
Lec20Lec20
Lec20
 
Lec18
Lec18Lec18
Lec18
 
Lec17
Lec17Lec17
Lec17
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Graphs
GraphsGraphs
Graphs
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
Data Structure: TREES
Data Structure: TREESData Structure: TREES
Data Structure: TREES
 
Red black trees
Red black treesRed black trees
Red black trees
 
Slide2
Slide2Slide2
Slide2
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Tree traversal techniques
Tree traversal  techniquesTree traversal  techniques
Tree traversal techniques
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Lec2
Lec2Lec2
Lec2
 

Destaque

Motogp Alcañiz 2011
Motogp Alcañiz 2011Motogp Alcañiz 2011
Motogp Alcañiz 2011Patri
 
Teague Allen ERL candidate
Teague Allen ERL candidateTeague Allen ERL candidate
Teague Allen ERL candidateTeague Allen
 
Using Data to Understand the Brain
Using Data to Understand the BrainUsing Data to Understand the Brain
Using Data to Understand the Brainjakehofman
 
Letter to arvind kejriwal dec 31 13 water issue
Letter to arvind kejriwal dec 31 13   water issueLetter to arvind kejriwal dec 31 13   water issue
Letter to arvind kejriwal dec 31 13 water issueMadhukar Varshney
 
Leonardoda vinci hispaintings-asearchforperfection1
Leonardoda vinci hispaintings-asearchforperfection1Leonardoda vinci hispaintings-asearchforperfection1
Leonardoda vinci hispaintings-asearchforperfection1filipj2000
 
7강 기업교육론 20110413
7강 기업교육론 201104137강 기업교육론 20110413
7강 기업교육론 20110413조현경
 
Butchart gardens, canada
Butchart gardens, canadaButchart gardens, canada
Butchart gardens, canadafilipj2000
 
Costing System example מערכת תמחיר - דוגמא
Costing System example      מערכת תמחיר - דוגמאCosting System example      מערכת תמחיר - דוגמא
Costing System example מערכת תמחיר - דוגמאoferyuval
 
A would-be nanopreneur's Thinkerings on Knowledge
A would-be nanopreneur's Thinkerings on KnowledgeA would-be nanopreneur's Thinkerings on Knowledge
A would-be nanopreneur's Thinkerings on KnowledgenanoKnowledge
 
Ellada patrida
Ellada patridaEllada patrida
Ellada patridafilipj2000
 
Ubuntu žaliems
Ubuntu žaliemsUbuntu žaliems
Ubuntu žaliemssirexas
 
3강 기업교육론 20110316(공유)
3강 기업교육론 20110316(공유)3강 기업교육론 20110316(공유)
3강 기업교육론 20110316(공유)조현경
 
Corporate Presentation
Corporate PresentationCorporate Presentation
Corporate Presentationdasherrod
 
Paris e suas igrejas
Paris e suas igrejasParis e suas igrejas
Paris e suas igrejasfilipj2000
 

Destaque (20)

Motogp Alcañiz 2011
Motogp Alcañiz 2011Motogp Alcañiz 2011
Motogp Alcañiz 2011
 
Kod
KodKod
Kod
 
Tecnicas
TecnicasTecnicas
Tecnicas
 
Teague Allen ERL candidate
Teague Allen ERL candidateTeague Allen ERL candidate
Teague Allen ERL candidate
 
Spectra-Profile
Spectra-ProfileSpectra-Profile
Spectra-Profile
 
Using Data to Understand the Brain
Using Data to Understand the BrainUsing Data to Understand the Brain
Using Data to Understand the Brain
 
Allatmamak
AllatmamakAllatmamak
Allatmamak
 
Alaska3
Alaska3Alaska3
Alaska3
 
Letter to arvind kejriwal dec 31 13 water issue
Letter to arvind kejriwal dec 31 13   water issueLetter to arvind kejriwal dec 31 13   water issue
Letter to arvind kejriwal dec 31 13 water issue
 
Maine prevention savings 11 22-10
Maine prevention savings 11 22-10Maine prevention savings 11 22-10
Maine prevention savings 11 22-10
 
Leonardoda vinci hispaintings-asearchforperfection1
Leonardoda vinci hispaintings-asearchforperfection1Leonardoda vinci hispaintings-asearchforperfection1
Leonardoda vinci hispaintings-asearchforperfection1
 
7강 기업교육론 20110413
7강 기업교육론 201104137강 기업교육론 20110413
7강 기업교육론 20110413
 
Butchart gardens, canada
Butchart gardens, canadaButchart gardens, canada
Butchart gardens, canada
 
Costing System example מערכת תמחיר - דוגמא
Costing System example      מערכת תמחיר - דוגמאCosting System example      מערכת תמחיר - דוגמא
Costing System example מערכת תמחיר - דוגמא
 
A would-be nanopreneur's Thinkerings on Knowledge
A would-be nanopreneur's Thinkerings on KnowledgeA would-be nanopreneur's Thinkerings on Knowledge
A would-be nanopreneur's Thinkerings on Knowledge
 
Ellada patrida
Ellada patridaEllada patrida
Ellada patrida
 
Ubuntu žaliems
Ubuntu žaliemsUbuntu žaliems
Ubuntu žaliems
 
3강 기업교육론 20110316(공유)
3강 기업교육론 20110316(공유)3강 기업교육론 20110316(공유)
3강 기업교육론 20110316(공유)
 
Corporate Presentation
Corporate PresentationCorporate Presentation
Corporate Presentation
 
Paris e suas igrejas
Paris e suas igrejasParis e suas igrejas
Paris e suas igrejas
 

Semelhante a Hashing Techniques and Functions Explained

Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7chidabdu
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingSam Light
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of techniclokaprasaadvs
 
lecture 10
lecture 10lecture 10
lecture 10sajinsc
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingzukun
 

Semelhante a Hashing Techniques and Functions Explained (20)

Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
 
13-hashing.ppt
13-hashing.ppt13-hashing.ppt
13-hashing.ppt
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
03.01 hash tables
03.01 hash tables03.01 hash tables
03.01 hash tables
 
Hashing
HashingHashing
Hashing
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Hashing
HashingHashing
Hashing
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of technic
 
lecture 10
lecture 10lecture 10
lecture 10
 
Hashing
HashingHashing
Hashing
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sorting
 
Hashing
HashingHashing
Hashing
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 

Mais de Anjneya Varshney (6)

Lec23
Lec23Lec23
Lec23
 
Lec22
Lec22Lec22
Lec22
 
Lec21
Lec21Lec21
Lec21
 
Lec19
Lec19Lec19
Lec19
 
Lec16
Lec16Lec16
Lec16
 
Lec13
Lec13Lec13
Lec13
 

Hashing Techniques and Functions Explained

  • 1. Hashing  Hash functions  Hash-code maps  Compression maps  Open addressing  LinearProbing  Double hashing
  • 2. Hash Functions  Need to choose a good hash function  quick to compute  distributes keys uniformly throughout the table  good hash functions are very rare – birthday paradox  How to deal with hashing non-integer keys:  find some way of turning keys into integers  eg. remove hyphen in 9635-8904 to get 96358904!  for a string, add up ASCII values of the characters of your string (e.g., java.lang.String.hashCode())  then use standard hash function on the integers
  • 3. From Keys to Indices  The mapping of keys to indices of a hash table is called a hash function  A hash function is usually the composition of two maps, a hash code map and a compression map.  An essential requirement of the hash function is to map equal keys to equal indices  A “good” hash function minimizes the probability of collisions
  • 4. Popular Hash-Code Maps  Integer cast: for numeric types with 32 bits or less, we can reinterpret the bits of the number as an int  Component sum: for numeric types with more than 32 bits (e.g., long and double), we can add the 32-bit components.  Why is the component-sum hash code bad for strings?
  • 5. Hash-Code Maps (2)  Polynomial accumulation: for strings of a natural language, combine the character values (ASCII or Unicode) a0a1 ... an-1 by viewing them as the coefficients of a polynomial: a0 + a1x + ...+ xn-1an-1  The polynomial is computed with Horner’s rule, ignoring overflows, at a fixed value x: a0 + x (a1 +x (a2+ ... x (an-2+ x an-1) ... ))  The choice x = 33, 37, 39, or 41 gives at most 6 collisions on a vocabulary of 50,000 English words
  • 6. Compression Maps  Use the remainder  h(k) = k mod m, k is the key, m the size of the table  Need to choose m  m = be (bad)  if m is a power of 2, h(k) gives the e least significant bits of k  all keys with the same ending go to the same place  m prime (good)  helps ensure uniform distribution  primes not too close to exact powers of 2
  • 7. Compression Maps (2)  Example  hash table for n = 2000 character strings  we don’t mind examining 3 elements  m = 701 a prime near 2000/3 but not near any power of 2
  • 8. Compression Maps (3)  Use  h(k) = m (k A mod 1)  k is the key, m the size of the table, and A is a constant 0<A<1  The steps involved  map 0...kmax into 0...kmax A  take the fractional part (mod 1)  map it into 0...m-1
  • 9. Compression Maps (4) Choice of m and A  value of m is not critical, typically use m = 2p  optimal choice of A depends on the characteristics of the data 5 1  Knuth says use A 2 (conjugate of the golden ratio) – Fibonacci hashing
  • 10. Compression Maps (5) Multiply, Add, and Divide (MAD): h(k) = |ak + b| mod N  eliminates patterns provided a is not a multiple of N  same formula used in linear congruential (pseudo) random number generators
  • 11. Universal Hashing  For any choice of hash function, there exists a bad set of identifiers  A malicious adversary could choose keys to be hashed such that all go into the same slot (bucket)  Average retrieval time is (n)  Solution a random hash function  choose hash function independently of keys!  create a set of hash functions H, from which h can be randomly selected
  • 12. Universal Hashing (2)  A collection H of hash functions is universal if for any randomly chosen f from H (and two keys k and l), Pr{f(k) = f(l)} 1/m
  • 13. More on Collisions  A key is mapped to an already occupied table location  what to do?!?  Use a collision handling technique  We’ve seen Chaining  Can also use Open Addressing  Probing  Double Hashing
  • 14. Open Addressing  Allelements are stored in the hash table (can fill up!), i.e., n m  Each table entry contains either an element or null  When searching for an element, systematically probe table slots
  • 15. Open Addressing (2)  Modify hash function to take the probe number i as the second parameter h :U 0,1,..., m 1 0,1,..., m 1  Hash function, h, determines the sequence of slots examined for a given key  Probe sequence for a given key k given by h(k ,0), h(k ,1),..., h(k , m 1) - a permutation of 0,1,..., m 1
  • 16. Linear Probing  If the current location is used, try the next table location LinearProbingInsert(k) if (table is full) error probe = h(k) while (table[probe] occupied) probe = (probe+1) mod m table[probe] = k  Uses less memory than chaining as one does not have to store all those links  Slower than chaining since one might have to walk along the table for a long time
  • 17. Linear Probing Example  h(k)= k mod 13  insert keys: 18 41 22 44 59 32 31 73 31 73 44 32 41 18 44 59 32 22 31 73
  • 18. Lookup in linear probing 41 18 44 59 32 22 31 73 0 1 2 3 4 5 6 7 8 9 10 11 12  To search for a key k we go to (k mod 13) and continue looking at successive locations till we find k or encounter an empty location.  Successful search: To search for 31 we go to (31 mod 13) = 5 and continue onto 6,7,8… till we find 31 at location 10  Unsuccessful search: To search for 33 we go to (33 mod 5 = 7) and continue till we encounter an empty location (12)
  • 19. Deletion in Linear Probing 41 18 44 59 32 22 31 73 0 1 2 3 4 5 6 7 8 9 10 11 12  To delete key 32 we first search for 32.  32 is found in location 8. Suppose we set this location to null.  Now if we search for 31 we will encounter a null location before seeing 31.  Lookup procedure would declare that 31 is not present.
  • 20. Deletion (2) 41 18 44 59 X 22 31 73 0 1 2 3 4 5 6 7 8 9 10 11 12  Instead of setting location 8 to null place a tombstone (a marker) there.  When lookup encounters a tombstone it ignores it and continues with next location.  If Insert comes across a tombstone it puts the element at that location and removes the tombstone.  Too many tombstones degrades lookup performance.  Rehash if there are too many tombstones.
  • 21. Double Hashing Uses two hash functions, h1, h2  h1(k) is the position in the table where we first check for key k  h2(k) determines the offset we use when searching for k  In linear probing h2(k) is always 1. DoubleHashingInsert(k) if (table is full) error probe = h1(k); offset = h2(k) while (table[probe] occupied) probe = (probe+offset) mod m table[probe] = k
  • 22. Double Hashing(2)  If m is prime, we will eventually examine every position in the table  Many of the same (dis)advantages as linear probing  Distributes keys more uniformly than linear probing
  • 23. Double Hashing Example  h1(k) = k mod 13  h2(k) = 8 – (k mod 8)  insert keys: 18 41 22 44 59 32 31 73 18 41 22 44 59 32 31 73 0 1 2 3 4 5 6 7 8 9 10 11 12
  • 24. Analysis of Double Hashing  The load factor is less than  We assume that every probe looks at a random location in the table.  1- fraction of the table is empty.  Expected number of probes required to find an empty location (unsuccessful search) is 1/(1- )
  • 25. Analysis (2)  Average no of probes for a successful search = average no of probes required to insert all the elements.  To insert an element we need to find an empty location. inserting Avg no of probes Total no of probes First m/2 <= 2 m Next m/4 <= 4 m Next m/8 <= 8 m
  • 26. Analysis(3)  No of probes required to insert m/2+m/4+m/8+…+m/2i elements = number of probes required to leave 2-i fraction of the table empty = m x i.  No of probes required to leave 1- fraction of the table empty = - m log (1- )  Average no. of probes required to insert n elements is - (m/n) log (1- ) = -(1/ ) log (1- )
  • 27. Expected Number of Probes  Load factor < 1 for probing  Analysis of probing uses uniform hashing assumption – any permutation is equally likely  What about linear probing and double hashing? unsuccessful successful chaining O(1 ) O(1 ) probing 1 1 1 O O ln 1 α α 1 α
  • 28. Expected Number of Probes (2)