SlideShare a Scribd company logo
1 of 21
Open addressing hashing is an alternative to
resolving collisions with linked list.
Separate chaining hashing has the
disadvantage of using linked lists.
The algorithm down a bit because of the time
to allocate new cells.
Its essentially requires the implements of a
second data structure.
Cells h0(x),h1(x),h2(x)... N.
F(0)=0 the function f, is the collision
resolution strategy.
The load factor ℷ=0.5
hi(x)=(hash(x)+f(i))
 The amounts to trying cells sequentially in
search of empty cell.
 The result of inserting keys {89,18,49,58,69}
into a hash table.
 The collision resolution strategy ,f(i)=i.
 The first collision occurs when 49 is inserted;
in spot 0,which is open.
Unsuccessful search ½(1+1/(1-ℷ)2)
Successful search ½(1+1/(1-ℷ))
0
1
2
3
4
5
6
7
8
9
 Linear Probing: after
checking spot h(k), try
spot h(k)+1, if that is full,
try h(k)+2, then h(k)+3,
etc.
Insert:
38
19
8
109
10
Empty table After 89 After 18 After 49 After 58 After 69
0 49 49 49
1 58 58
2 69
3
4
5
6
7
8 18 18 18 18
9 89 89 89 89 89
f(i) = i2
 Probe sequence:
0th probe = h(k) mod Table size
1th probe = (h(k) + 1) mod Table size
2th probe = (h(k) + 4) mod Table Size
3th probe = (h(k) + 9) mod Table Size
. . .
ith probe = (h(k) + i2) mod Table Size
 show for all 0  i,j  size/2 and i  j
(h(x) + i2) mod size  (h(x) + j2) mod size
 by contradiction: suppose that for some i  j:
(h(x) + i2) mod size = (h(x) + j2) mod size
 i2 mod size = j2 mod size
 (i2 - j2) mod size = 0
 [(i + j)(i - j)] mod size = 0
Because size is prime(i-j)or (i+j) must be zero, and
neither can be
Empty table After 89 After 18 After 49 After 58 After 69
0 49 49 49
1
2 58 58
3 69
4
5
6
7
8 18 18 18 18
9 89 89 89 89 89
The last collision resolution method
examine is double hashing.
Double hashing f(i)=i⋅hash2(x).
Hash function to x and probe at a
distance hash2(x),2hash2(x)…,
A function such as hash2(x)=R-(x mod
R), with R a prime smaller than Table
Size.
f(i) = i * g(k)
where g is a second hash function
Probe sequence:
0th probe = h(k) mod Table Size
1th probe = (h(k) + g(k)) mod Table Size
2th probe = (h(k) + 2*g(k)) mod Table Size
3th probe = (h(k) + 3*g(k)) mod Table Size
. . .
ith probe = (h(k) + i*g(k)) mod Table Size
 Insert these values into the hash table in this
order. Resolve any collisions with double hashing:
13
28
33
147
43
Hash Functions:
H(K) = K mod M
H2(K) = 1 + ((K/M) mod (M-1))
 When the table gets too full, create a bigger
table (usually 2x as large) and hash all the
items from the original table into the new
table.
To rehash
1) half full ( = 0.5)
2) when an insertion fails
3) some other threshold
0 6
1 15
2
3 24
4
5
6 13
0 6
1 15
2 23
3 24
4
5
6 13
B) Open addressing hash
table with linear probing
after 23 is inserted
A) Open addressing hash
table with linear probing
with input 13,15,6,24
0
1
2
3 6
4 23
5 24
6
7
8
9 13
10
11 15
 Extendible hashing accesses the data stored in
buckets indirectly through an index that is
dynamically adjusted to reflect changes in the file.
 A hash function applied to a certain key indicates
a position in the index and not in the file (or table
or keys). Values returned by such a hash function
are called pseudo keys.
00 01 10 11
(2)
000 100
001 010
001 010
001 011
(2)
010 100
011 000
(2)
100 000
101 000
101 100
101 110
(2)
111 000
111 001
000 001 010 011 100 101 110 111
(2)
000 100
001 000
001 010
001 011
(2)
010 100
011 000
(2)
100 000
100 100
(3)
100 000
100 100
(2)
111 000
111 001
000 001 010 011 100 101 110 111
(3)
000 000
000 100
(3)
001 000
001 010
001 110
(2)
010 100
011 000
(3)
100 000
100 100
(2)
101 000
101 100
101 110
(2)
111 000
111 001
Expandable Hashing
But binary tree is used to store an index on the buckets.
Dynamic Hashing
multiple binary trees are used.
Outcome:
- To shorten the search.
- Based on the key --- select what tree to search.
 Larson method
 Index is simplified to be represented as a set of
binary trees.
 Height of each tree is limited.
 h(x) is searched in ALL trees.
 Time: m – trees, k keys in each max, overall:
m*l gk.
 Advantage: shorter search time in index file

More Related Content

What's hot

Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 

What's hot (20)

Searching
SearchingSearching
Searching
 
Heap sort
Heap sortHeap sort
Heap sort
 
RSA ALGORITHM
RSA ALGORITHMRSA ALGORITHM
RSA ALGORITHM
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Hashing
HashingHashing
Hashing
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Hashing
HashingHashing
Hashing
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Modern symmetric cipher
Modern symmetric cipherModern symmetric cipher
Modern symmetric cipher
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
AES-Advanced Encryption Standard
AES-Advanced Encryption StandardAES-Advanced Encryption Standard
AES-Advanced Encryption Standard
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 

Similar to Open addressiing &rehashing,extendiblevhashing

Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
Sajid Marwat
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
Haripritha
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
chidabdu
 

Similar to Open addressiing &rehashing,extendiblevhashing (20)

Hashing
HashingHashing
Hashing
 
Data Structures- Hashing
Data Structures- Hashing Data Structures- Hashing
Data Structures- Hashing
 
Lec5
Lec5Lec5
Lec5
 
Lec5
Lec5Lec5
Lec5
 
Hashing
HashingHashing
Hashing
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
03.01 hash tables
03.01 hash tables03.01 hash tables
03.01 hash tables
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
QMC: Operator Splitting Workshop, Forward-Backward Splitting Algorithm withou...
QMC: Operator Splitting Workshop, Forward-Backward Splitting Algorithm withou...QMC: Operator Splitting Workshop, Forward-Backward Splitting Algorithm withou...
QMC: Operator Splitting Workshop, Forward-Backward Splitting Algorithm withou...
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Bitwise
BitwiseBitwise
Bitwise
 
Differential calculus
Differential calculus  Differential calculus
Differential calculus
 
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
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 
chapter3 (2).pdf
chapter3 (2).pdfchapter3 (2).pdf
chapter3 (2).pdf
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 

More from SangeethaSasi1 (20)

L4 multiplexing & multiple access 16
L4 multiplexing & multiple access 16L4 multiplexing & multiple access 16
L4 multiplexing & multiple access 16
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab
 
Mc ppt
Mc pptMc ppt
Mc ppt
 
Mc ppt
Mc pptMc ppt
Mc ppt
 
Dip pppt
Dip ppptDip pppt
Dip pppt
 
Web techh
Web techhWeb techh
Web techh
 
Web tech
Web techWeb tech
Web tech
 
Vani wt
Vani wtVani wt
Vani wt
 
Vani dbms
Vani dbmsVani dbms
Vani dbms
 
Hema wt (1)
Hema wt (1)Hema wt (1)
Hema wt (1)
 
Hema rdbms
Hema rdbmsHema rdbms
Hema rdbms
 
Web tech
Web techWeb tech
Web tech
 
Web tech
Web techWeb tech
Web tech
 
Dbms
DbmsDbms
Dbms
 
Vani
VaniVani
Vani
 
Hema se
Hema seHema se
Hema se
 
Software
SoftwareSoftware
Software
 
Operating system
Operating systemOperating system
Operating system
 
Dataminng
DataminngDataminng
Dataminng
 
System calls
System callsSystem calls
System calls
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

Open addressiing &rehashing,extendiblevhashing

  • 1.
  • 2. Open addressing hashing is an alternative to resolving collisions with linked list. Separate chaining hashing has the disadvantage of using linked lists. The algorithm down a bit because of the time to allocate new cells. Its essentially requires the implements of a second data structure.
  • 3. Cells h0(x),h1(x),h2(x)... N. F(0)=0 the function f, is the collision resolution strategy. The load factor ℷ=0.5 hi(x)=(hash(x)+f(i))
  • 4.  The amounts to trying cells sequentially in search of empty cell.  The result of inserting keys {89,18,49,58,69} into a hash table.  The collision resolution strategy ,f(i)=i.  The first collision occurs when 49 is inserted; in spot 0,which is open. Unsuccessful search ½(1+1/(1-ℷ)2) Successful search ½(1+1/(1-ℷ))
  • 5. 0 1 2 3 4 5 6 7 8 9  Linear Probing: after checking spot h(k), try spot h(k)+1, if that is full, try h(k)+2, then h(k)+3, etc. Insert: 38 19 8 109 10
  • 6. Empty table After 89 After 18 After 49 After 58 After 69 0 49 49 49 1 58 58 2 69 3 4 5 6 7 8 18 18 18 18 9 89 89 89 89 89
  • 7. f(i) = i2  Probe sequence: 0th probe = h(k) mod Table size 1th probe = (h(k) + 1) mod Table size 2th probe = (h(k) + 4) mod Table Size 3th probe = (h(k) + 9) mod Table Size . . . ith probe = (h(k) + i2) mod Table Size
  • 8.  show for all 0  i,j  size/2 and i  j (h(x) + i2) mod size  (h(x) + j2) mod size  by contradiction: suppose that for some i  j: (h(x) + i2) mod size = (h(x) + j2) mod size  i2 mod size = j2 mod size  (i2 - j2) mod size = 0  [(i + j)(i - j)] mod size = 0 Because size is prime(i-j)or (i+j) must be zero, and neither can be
  • 9. Empty table After 89 After 18 After 49 After 58 After 69 0 49 49 49 1 2 58 58 3 69 4 5 6 7 8 18 18 18 18 9 89 89 89 89 89
  • 10. The last collision resolution method examine is double hashing. Double hashing f(i)=i⋅hash2(x). Hash function to x and probe at a distance hash2(x),2hash2(x)…, A function such as hash2(x)=R-(x mod R), with R a prime smaller than Table Size.
  • 11. f(i) = i * g(k) where g is a second hash function Probe sequence: 0th probe = h(k) mod Table Size 1th probe = (h(k) + g(k)) mod Table Size 2th probe = (h(k) + 2*g(k)) mod Table Size 3th probe = (h(k) + 3*g(k)) mod Table Size . . . ith probe = (h(k) + i*g(k)) mod Table Size
  • 12.  Insert these values into the hash table in this order. Resolve any collisions with double hashing: 13 28 33 147 43 Hash Functions: H(K) = K mod M H2(K) = 1 + ((K/M) mod (M-1))
  • 13.  When the table gets too full, create a bigger table (usually 2x as large) and hash all the items from the original table into the new table. To rehash 1) half full ( = 0.5) 2) when an insertion fails 3) some other threshold
  • 14. 0 6 1 15 2 3 24 4 5 6 13 0 6 1 15 2 23 3 24 4 5 6 13 B) Open addressing hash table with linear probing after 23 is inserted A) Open addressing hash table with linear probing with input 13,15,6,24
  • 15. 0 1 2 3 6 4 23 5 24 6 7 8 9 13 10 11 15
  • 16.  Extendible hashing accesses the data stored in buckets indirectly through an index that is dynamically adjusted to reflect changes in the file.  A hash function applied to a certain key indicates a position in the index and not in the file (or table or keys). Values returned by such a hash function are called pseudo keys.
  • 17. 00 01 10 11 (2) 000 100 001 010 001 010 001 011 (2) 010 100 011 000 (2) 100 000 101 000 101 100 101 110 (2) 111 000 111 001
  • 18. 000 001 010 011 100 101 110 111 (2) 000 100 001 000 001 010 001 011 (2) 010 100 011 000 (2) 100 000 100 100 (3) 100 000 100 100 (2) 111 000 111 001
  • 19. 000 001 010 011 100 101 110 111 (3) 000 000 000 100 (3) 001 000 001 010 001 110 (2) 010 100 011 000 (3) 100 000 100 100 (2) 101 000 101 100 101 110 (2) 111 000 111 001
  • 20. Expandable Hashing But binary tree is used to store an index on the buckets. Dynamic Hashing multiple binary trees are used. Outcome: - To shorten the search. - Based on the key --- select what tree to search.
  • 21.  Larson method  Index is simplified to be represented as a set of binary trees.  Height of each tree is limited.  h(x) is searched in ALL trees.  Time: m – trees, k keys in each max, overall: m*l gk.  Advantage: shorter search time in index file