SlideShare a Scribd company logo
1 of 21
HASHING
(Separate chaining, Closed Hashing)
K.HARIPRITHA.
M.Sc(Info Tech).
Nadar Saraswathi college of arts and science.
Synopsis:
 SEPARATE CHAINING
 Open Hashtable.
 Type declaration for separate chaining.
 Insert routine for separate chaining Hash
Table
 Initialization routine for separate chaining
Hash table.
OPEN ADDRESSING
Linear Probing
Quadric Probing
Double Hashing
SEPARATE CHANNING
(Open hashing)
 Open hashing is to keep a list of all elements that hash to
the same value.
 In the space is tight , it might be preferable to avoid their
use.
 In this section that the keys are the first 10 perfect squares
and that the hash function is simply Hash(X)=X mod 10.
 That we use the hash function to determine which list to
traverse this list in the normal manner , returning the
position where the item is found.
OPEN HASH TABLE
 To be involve insert. we travese down the appropriate list to
check then the element is placed.
 If the element turns out to be new it is inserted either at the
front of the list or at the end of the list.
 This is easily addressed while the code is being written.In the
new element are sometimes are inserted at thre front of the list.The class
specification required to implement the open hashing.
 Last item is accessed by the accessing item in the current list
with the ()operator.
 The lists are automatically initialized by the list constructor.
 Routines to copy and reinitialize are provided. Line 4 through 6 allocate a
hash table structure.
 H will be point to s structure containing an integer and a pointer to a
list.Line 7 sets table size to a prime number and lines 8 through 10 attempt to
allocate an array of list.
 Implementation uses header allocate one header per list and set its next field
to NULL.
Type declaration for separate chaining
hash table
#ifndef_hashsep_H
Struct ListNode;
Typedef struct ListNode *Position;
Struct HashTbl;
typedef struct HashTbl *Hash Table;
HashTable Initialize (int Tablesize);
Void DestroyTable (HashTable H);
Position Find (ElementType Key,
HashTable);
Void insert(ElementType key, HashTable
H);
Element type retrive(position p);
/*Routines such as Delete and make
empty are omitted */
#endif /*_Hashsep_H*/
/* Place in the implementation file*/
struct ListNode
{
ElementType Element;
Position Next;
};
Typedef Position Lists;
/*List *The List will be an array of
lists,allocated later
/*The lists use header (for simplicity,*),*/
/*though this wastes space*/
Struct HashTb
{
int TableSize;
Lists*TheLists;
};
Insert routine for separate chaining Hash table
Void
Insert(ElementType key,HashTable H)
{
Position pos,Newcell;
List L;
/*1*/ Pos=Find(key, H);
/*2*/if (pos==NULL)/*Key is not found*/
/*3*/Newcell=malloc(sizeof(struct ListNode));
/*4*/if(Newcell==NULL)
/*5*/ Fatalerror(“Out of space”);
else
{
/*6*/ L=H->The Lists[Hash(Key,H->TableSize)];
/*7*/Newcell->Next=L->Next;
/*8*/Newcell->Element=key; /*Probably need strcpy!*/
/*9*/L->Next =NewCell;
}
}
}
Initialization routine for separate
chaining hash table
HashTable
InitializeTable(int Tablesize)
{
HashTable H;
int I;
/*1*/ if (TableSize<MinTableSize)
{
/*2*/ Error (“table size too small”);
/*3*/ return NULL;
}
/*Allocate table*/
/*4*/H=malloc(sizeof(struct HashTbl));
/*5*/if(H==NULL)
/*6*/FatalError(“Out of space!!!”);
/*7*/H->Tablesize = Nextprime(TableSize)
/*Allocate arraay of list*/
/*8*/H->The lists =malloc (sizeof(List)*H-
>TableSize);
/*9*/if (H->TheLists==NULL)
/*10*/ FatalError(“Out of space!!!”);
/*Allocate list header*/
/*11*/ for (i=0;i<H->TableSize;i++)
{
/*12*/H->The Lists [i]=malloc(Sizeof(struct
ListNode));
/*13*/if (H->The lists[i]==NULL)
/*14*/FatalError(“Out of space!!!”);
else
/*15*/ H->The lists[i]->Next=NULL;
}
/*16*/ return H;
}
 The deletion routine is a straightforward implementation
of deletion in a linked list,so will not bother with it here.
 If the table is large and the hash function is good,all the
lists should be short so it is not worthwhile to try anything
cmplicated.
 The loaded factor ʎ of a hash table to the ratio of the
number element to the hash table to the table
size.(ex:above ʎ=1.0. The average length of the list is ʎ)
 The number of the link to traverse is ʎ on average.A
successful search requires that about 1+(ʎ+2)link be
traversed.
 The general rule for separate chaining hashing is to make
the table size about the large as the number of the element
expected
OPEN ADDRESSING
 Open addressing, or closed hashing, is a method
of collision resolution in hash tables.
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))
LINEAR PROBING
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 using the same hash function.
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
OPEN ADDRESSING HASH TABLE WITH
LINEAR PROBING
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
Quadratic Probing
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
Quadratic Probing:
Success guarantee for  < ½
• 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
OPEN ADDRESSING HASH TABLE WITH
QUADRATIC PROBING
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
DOUBLE HASHING
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
Resolving Collisions with Double
Hashing
 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))
THANK YOU

More Related Content

What's hot

Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sortingsajinis3
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST Kathirvel Ayyaswamy
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
GCD of n Numbers
GCD of n NumbersGCD of n Numbers
GCD of n NumbersSaikat Roy
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithmAamir Sohail
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in pythonhydpy
 
Binary search tree
Binary search treeBinary search tree
Binary search treeKousalya M
 

What's hot (20)

Heap_Sort1.pptx
Heap_Sort1.pptxHeap_Sort1.pptx
Heap_Sort1.pptx
 
Double Hashing.pptx
Double Hashing.pptxDouble Hashing.pptx
Double Hashing.pptx
 
Binary search
Binary searchBinary search
Binary search
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Hash table
Hash tableHash table
Hash table
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
GCD of n Numbers
GCD of n NumbersGCD of n Numbers
GCD of n Numbers
 
DATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdfDATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdf
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
CS8391 Data Structures 2 mark Questions - Anna University Questions
CS8391 Data Structures 2 mark Questions - Anna University QuestionsCS8391 Data Structures 2 mark Questions - Anna University Questions
CS8391 Data Structures 2 mark Questions - Anna University Questions
 
Hashing
HashingHashing
Hashing
 
Big O Notation.ppt
Big O Notation.pptBig O Notation.ppt
Big O Notation.ppt
 
Bit manipulation
Bit manipulationBit manipulation
Bit manipulation
 

Similar to HASHING TECHNIQUES EXPLAINED

Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithmfarhankhan89766
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...Subhajit Sahu
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7chidabdu
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniyaTutorialsDuniya.com
 
Data Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table pptData Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table pptJUSTFUN40
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Kuntal Bhowmick
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashingchidabdu
 

Similar to HASHING TECHNIQUES EXPLAINED (20)

Hashing
HashingHashing
Hashing
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Hashing
HashingHashing
Hashing
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Hashing
HashingHashing
Hashing
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm
 
Hash function
Hash functionHash function
Hash function
 
Hashing
HashingHashing
Hashing
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Lec5
Lec5Lec5
Lec5
 
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
 
Hash pre
Hash preHash pre
Hash pre
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
 
Presentation Of Analysis
Presentation Of Analysis  Presentation Of Analysis
Presentation Of Analysis
 
Data Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table pptData Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table ppt
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
 

More from Haripritha

Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce scriptHaripritha
 
Wireless sensor networks
Wireless sensor networksWireless sensor networks
Wireless sensor networksHaripritha
 
Operating system
Operating systemOperating system
Operating systemHaripritha
 
Presentation 2
Presentation 2Presentation 2
Presentation 2Haripritha
 
Computer Organization
Computer OrganizationComputer Organization
Computer OrganizationHaripritha
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++Haripritha
 

More from Haripritha (9)

Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce script
 
Wireless sensor networks
Wireless sensor networksWireless sensor networks
Wireless sensor networks
 
Datamining
DataminingDatamining
Datamining
 
Operating system
Operating systemOperating system
Operating system
 
Java
JavaJava
Java
 
Presentation 2
Presentation 2Presentation 2
Presentation 2
 
Computer Organization
Computer OrganizationComputer Organization
Computer Organization
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
encoding
encodingencoding
encoding
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

HASHING TECHNIQUES EXPLAINED

  • 1. HASHING (Separate chaining, Closed Hashing) K.HARIPRITHA. M.Sc(Info Tech). Nadar Saraswathi college of arts and science.
  • 2. Synopsis:  SEPARATE CHAINING  Open Hashtable.  Type declaration for separate chaining.  Insert routine for separate chaining Hash Table  Initialization routine for separate chaining Hash table. OPEN ADDRESSING Linear Probing Quadric Probing Double Hashing
  • 3. SEPARATE CHANNING (Open hashing)  Open hashing is to keep a list of all elements that hash to the same value.  In the space is tight , it might be preferable to avoid their use.  In this section that the keys are the first 10 perfect squares and that the hash function is simply Hash(X)=X mod 10.  That we use the hash function to determine which list to traverse this list in the normal manner , returning the position where the item is found.
  • 5.  To be involve insert. we travese down the appropriate list to check then the element is placed.  If the element turns out to be new it is inserted either at the front of the list or at the end of the list.  This is easily addressed while the code is being written.In the new element are sometimes are inserted at thre front of the list.The class specification required to implement the open hashing.  Last item is accessed by the accessing item in the current list with the ()operator.  The lists are automatically initialized by the list constructor.  Routines to copy and reinitialize are provided. Line 4 through 6 allocate a hash table structure.  H will be point to s structure containing an integer and a pointer to a list.Line 7 sets table size to a prime number and lines 8 through 10 attempt to allocate an array of list.  Implementation uses header allocate one header per list and set its next field to NULL.
  • 6. Type declaration for separate chaining hash table #ifndef_hashsep_H Struct ListNode; Typedef struct ListNode *Position; Struct HashTbl; typedef struct HashTbl *Hash Table; HashTable Initialize (int Tablesize); Void DestroyTable (HashTable H); Position Find (ElementType Key, HashTable); Void insert(ElementType key, HashTable H); Element type retrive(position p); /*Routines such as Delete and make empty are omitted */ #endif /*_Hashsep_H*/ /* Place in the implementation file*/ struct ListNode { ElementType Element; Position Next; }; Typedef Position Lists; /*List *The List will be an array of lists,allocated later /*The lists use header (for simplicity,*),*/ /*though this wastes space*/ Struct HashTb { int TableSize; Lists*TheLists; };
  • 7. Insert routine for separate chaining Hash table Void Insert(ElementType key,HashTable H) { Position pos,Newcell; List L; /*1*/ Pos=Find(key, H); /*2*/if (pos==NULL)/*Key is not found*/ /*3*/Newcell=malloc(sizeof(struct ListNode)); /*4*/if(Newcell==NULL) /*5*/ Fatalerror(“Out of space”); else { /*6*/ L=H->The Lists[Hash(Key,H->TableSize)]; /*7*/Newcell->Next=L->Next; /*8*/Newcell->Element=key; /*Probably need strcpy!*/ /*9*/L->Next =NewCell; } } }
  • 8. Initialization routine for separate chaining hash table HashTable InitializeTable(int Tablesize) { HashTable H; int I; /*1*/ if (TableSize<MinTableSize) { /*2*/ Error (“table size too small”); /*3*/ return NULL; } /*Allocate table*/ /*4*/H=malloc(sizeof(struct HashTbl)); /*5*/if(H==NULL) /*6*/FatalError(“Out of space!!!”); /*7*/H->Tablesize = Nextprime(TableSize) /*Allocate arraay of list*/ /*8*/H->The lists =malloc (sizeof(List)*H- >TableSize); /*9*/if (H->TheLists==NULL) /*10*/ FatalError(“Out of space!!!”); /*Allocate list header*/ /*11*/ for (i=0;i<H->TableSize;i++) { /*12*/H->The Lists [i]=malloc(Sizeof(struct ListNode)); /*13*/if (H->The lists[i]==NULL) /*14*/FatalError(“Out of space!!!”); else /*15*/ H->The lists[i]->Next=NULL; } /*16*/ return H; }
  • 9.  The deletion routine is a straightforward implementation of deletion in a linked list,so will not bother with it here.  If the table is large and the hash function is good,all the lists should be short so it is not worthwhile to try anything cmplicated.  The loaded factor ʎ of a hash table to the ratio of the number element to the hash table to the table size.(ex:above ʎ=1.0. The average length of the list is ʎ)  The number of the link to traverse is ʎ on average.A successful search requires that about 1+(ʎ+2)link be traversed.  The general rule for separate chaining hashing is to make the table size about the large as the number of the element expected
  • 10. OPEN ADDRESSING  Open addressing, or closed hashing, is a method of collision resolution in hash tables. 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.
  • 11. 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))
  • 12. LINEAR PROBING 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 using the same hash function. 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-ℷ))
  • 13. 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
  • 14. OPEN ADDRESSING HASH TABLE WITH LINEAR PROBING 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
  • 15. Quadratic Probing 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
  • 16. Quadratic Probing: Success guarantee for  < ½ • 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
  • 17. OPEN ADDRESSING HASH TABLE WITH QUADRATIC PROBING 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
  • 18. DOUBLE HASHING 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.
  • 19. 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
  • 20. Resolving Collisions with Double Hashing  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))