SlideShare a Scribd company logo
1 of 14
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NACC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Subject- Data Structures-I(CO203)
Unit III- Collision Resolution Strtergies
Collision Resolution Strategies
• If the element to be inserted is mapped with the same location where an
element is already inserted then collision occurs and it must be resolved.
• Open Hashing:
• Allows record to be stored in unlimited space(which can be a hard disk).
• It places no limitation in the size of tables.
• Records are partitioned into b buckets.
• Each bucket in the hash table is header of the linked list of records mapped to
that buckets. e.g. separate chaining.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 2
• Closed Hashing:
• uses fixed space for storage and thus limits the size of hash table.
• In this technique, hash table keeps the elements in the bucket itself.no. of records
depends on the no. of slots in bucket.
• It involves open addressing techniques like Linear probing, Quadratic probing,
Rehashing etc.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 3
 Separate Chaining(Open Hashing):
• Separate list of all elements mapped to the same value is maintained.
• The idea is to make each bucket of hash table point to a linked list of records that
have same hash function value.
• It is used when there is no limit on memory space.
• Let us consider a simple hash function as “key mod 7” and sequence of keys as
50, 700, 76, 85, 92, 73, 101.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 4
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 5
• in practice the table size can be significantly large and the hash function can be
even more complex, also the data being hashed would be more complex and
non-primitive, but the idea remains the same.
• Advantages:
1) Simple to implement. We require a good hash function to guarantee even
distribution of the values.
2) Hash table never fills up, we can always add more elements to the chain.
3) Less sensitive to the hash function or load factors.
4) It is mostly used when it is unknown how many and how frequently keys may
be inserted or deleted.DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 6
• Disadvantages:
1) Cache performance of chaining is not good as keys are stored using a linked
list. Open addressing provides better cache performance as everything is stored
in the same table.
2) Wastage of Space (Some Parts of hash table are never used)
3) The lookups/inserts/updates can become linear [O(N)] instead of constant time
[O(1)] if the hash function has too many collisions.
4) Uses extra space for links.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 7
• Operations on Hash Table:
1.Initialize(): headers of all lists are set to NULL.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 8
#define MAX 10
struct node
{
int prn;
char name[10];
char name[10];
struct node *next;
} node *ht[MAX];
void initialize()
{
int i;
for(i=0;i<MAX;i++)
{
ht[i]=NULL;
}
• Insert()- insert element at the end link list
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 9
void insert()
{
int addr,key,name;
node *ptr,*temp;
cout<<“enter student prn”;
cin>>prn;
cout<<“enter name”;
cin>> name;
temp=new node;
temp->prn=prn;
temp->name=name;
addr=key % MAX;
if(ht[addr]==NULL)
{
ht[addr]=temp;
else
{
ptr=ht[addr];
while(ptr->next!=NULL)
{
ptr=ptr->next;
}
ptr->next=temp;
}
}
e.g. 0,1,4,7,11,24,67,33,34,77,53 No. of
bucket=10
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 10
0
1
2
3
4
5
6
7
8
9
700 NULL
e.g. 50,700,76,85,92,73,101 size of table is 7
50 85 92 NULL
73 101 NULL
76 NULL
• Search() -> search an
element in the hash
table
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 11
node * search()
{
int addr,key;
cout<<“Enter the element to be search”;
cin<<key;
addr=key%MAX;
ptr=ht[addr]
while(ptr!=NULL && key!=ptr->data)
{
ptr=ptr->next;
}
if(key==ptr->data)
{
cout<<“Key Found”;
return(ptr);
}
return NULL; }
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 12
void display()
{
hash *ptr;
for(i=0;i<MAX;i++)
{
ptr=ht[i];
while(ptr!=NULL)
{
cout<<ptr->prn<<“t”<<ptr->name<<“->”;
ptr=ptr->next;
}
}
}
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 13
Delete()
{
int addr;
node *ptr,*prev,*temp;
cout<<“enter data to be
deleted”;
cin>>key;
addr=key%MAX;
prev=ptr=ht[addr];
if(ptr->data==key)
{
prev=prev->next;
ht[addr]=prev;
delete(ptr);
}
else
{
while(ptr->data!=key && ptr->next!=NULL)
{
prev=ptr;
ptr=ptr->next;
}
if(ptr->data==key)
{
prev->next=ptr->next;
delete(ptr);
}
}//end of else
} //end of function
• Time Complexity:
Search= O(1+α ) where α is loading factor
Insert/Delete: O(1+α )
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 14

More Related Content

What's hot

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and boundAbhishek Singh
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure Meghaj Mallick
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahniHitesh Wagle
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |MdSaiful14
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of LanguageDipankar Boruah
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic AlgorithmsDipankar Boruah
 

What's hot (20)

ADA_2_Analysis of Algorithms
ADA_2_Analysis of AlgorithmsADA_2_Analysis of Algorithms
ADA_2_Analysis of Algorithms
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
single linked list
single linked listsingle linked list
single linked list
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Presentation-Merge Sort
Presentation-Merge SortPresentation-Merge Sort
Presentation-Merge Sort
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic Algorithms
 

Similar to Collision resolution.pptx

unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxBabaShaikh3
 
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 TaipeiPostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 TaipeiSatoshi Nagayasu
 
The life of a query (oracle edition)
The life of a query (oracle edition)The life of a query (oracle edition)
The life of a query (oracle edition)maclean liu
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with EpsilonSina Madani
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQLSatoshi Nagayasu
 
Data Step Hash Object vs SQL Join
Data Step Hash Object vs SQL JoinData Step Hash Object vs SQL Join
Data Step Hash Object vs SQL JoinGeoff Ness
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuningAnil Pandey
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial IGagan Deep
 
RaptorX: Building a 10X Faster Presto with hierarchical cache
RaptorX: Building a 10X Faster Presto with hierarchical cacheRaptorX: Building a 10X Faster Presto with hierarchical cache
RaptorX: Building a 10X Faster Presto with hierarchical cacheAlluxio, Inc.
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesssuserec8a711
 
Design of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore ArchitectureDesign of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore ArchitectureLuiz Henrique Zambom Santana
 
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choiTajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choiData Con LA
 
Linked list basics
Linked list basicsLinked list basics
Linked list basicsRajesh Kumar
 
Efficient top k retrieval on massive data
Efficient top k retrieval on massive dataEfficient top k retrieval on massive data
Efficient top k retrieval on massive dataPvrtechnologies Nellore
 

Similar to Collision resolution.pptx (20)

closed hashing.pptx
closed hashing.pptxclosed hashing.pptx
closed hashing.pptx
 
closed hashing.pptx
closed hashing.pptxclosed hashing.pptx
closed hashing.pptx
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
 
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 TaipeiPostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
 
The life of a query (oracle edition)
The life of a query (oracle edition)The life of a query (oracle edition)
The life of a query (oracle edition)
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with Epsilon
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
Data Step Hash Object vs SQL Join
Data Step Hash Object vs SQL JoinData Step Hash Object vs SQL Join
Data Step Hash Object vs SQL Join
 
02-hashing.pdf
02-hashing.pdf02-hashing.pdf
02-hashing.pdf
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial I
 
RaptorX: Building a 10X Faster Presto with hierarchical cache
RaptorX: Building a 10X Faster Presto with hierarchical cacheRaptorX: Building a 10X Faster Presto with hierarchical cache
RaptorX: Building a 10X Faster Presto with hierarchical cache
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
 
Design of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore ArchitectureDesign of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore Architecture
 
DB
DBDB
DB
 
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choiTajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
 
LEXICAL ANALYZER
LEXICAL ANALYZERLEXICAL ANALYZER
LEXICAL ANALYZER
 
Linked list basics
Linked list basicsLinked list basics
Linked list basics
 
Efficient top k retrieval on massive data
Efficient top k retrieval on massive dataEfficient top k retrieval on massive data
Efficient top k retrieval on massive data
 

Recently uploaded

ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 

Recently uploaded (20)

ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 

Collision resolution.pptx

  • 1. Sanjivani Rural Education Society’s Sanjivani College of Engineering, Kopargaon-423 603 (An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune) NACC ‘A’ Grade Accredited, ISO 9001:2015 Certified Department of Computer Engineering (NBA Accredited) Subject- Data Structures-I(CO203) Unit III- Collision Resolution Strtergies
  • 2. Collision Resolution Strategies • If the element to be inserted is mapped with the same location where an element is already inserted then collision occurs and it must be resolved. • Open Hashing: • Allows record to be stored in unlimited space(which can be a hard disk). • It places no limitation in the size of tables. • Records are partitioned into b buckets. • Each bucket in the hash table is header of the linked list of records mapped to that buckets. e.g. separate chaining. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 2
  • 3. • Closed Hashing: • uses fixed space for storage and thus limits the size of hash table. • In this technique, hash table keeps the elements in the bucket itself.no. of records depends on the no. of slots in bucket. • It involves open addressing techniques like Linear probing, Quadratic probing, Rehashing etc. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 3
  • 4.  Separate Chaining(Open Hashing): • Separate list of all elements mapped to the same value is maintained. • The idea is to make each bucket of hash table point to a linked list of records that have same hash function value. • It is used when there is no limit on memory space. • Let us consider a simple hash function as “key mod 7” and sequence of keys as 50, 700, 76, 85, 92, 73, 101. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 4
  • 5. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 5
  • 6. • in practice the table size can be significantly large and the hash function can be even more complex, also the data being hashed would be more complex and non-primitive, but the idea remains the same. • Advantages: 1) Simple to implement. We require a good hash function to guarantee even distribution of the values. 2) Hash table never fills up, we can always add more elements to the chain. 3) Less sensitive to the hash function or load factors. 4) It is mostly used when it is unknown how many and how frequently keys may be inserted or deleted.DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 6
  • 7. • Disadvantages: 1) Cache performance of chaining is not good as keys are stored using a linked list. Open addressing provides better cache performance as everything is stored in the same table. 2) Wastage of Space (Some Parts of hash table are never used) 3) The lookups/inserts/updates can become linear [O(N)] instead of constant time [O(1)] if the hash function has too many collisions. 4) Uses extra space for links. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 7
  • 8. • Operations on Hash Table: 1.Initialize(): headers of all lists are set to NULL. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 8 #define MAX 10 struct node { int prn; char name[10]; char name[10]; struct node *next; } node *ht[MAX]; void initialize() { int i; for(i=0;i<MAX;i++) { ht[i]=NULL; }
  • 9. • Insert()- insert element at the end link list DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 9 void insert() { int addr,key,name; node *ptr,*temp; cout<<“enter student prn”; cin>>prn; cout<<“enter name”; cin>> name; temp=new node; temp->prn=prn; temp->name=name; addr=key % MAX; if(ht[addr]==NULL) { ht[addr]=temp; else { ptr=ht[addr]; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=temp; } }
  • 10. e.g. 0,1,4,7,11,24,67,33,34,77,53 No. of bucket=10 DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 10 0 1 2 3 4 5 6 7 8 9 700 NULL e.g. 50,700,76,85,92,73,101 size of table is 7 50 85 92 NULL 73 101 NULL 76 NULL
  • 11. • Search() -> search an element in the hash table DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 11 node * search() { int addr,key; cout<<“Enter the element to be search”; cin<<key; addr=key%MAX; ptr=ht[addr] while(ptr!=NULL && key!=ptr->data) { ptr=ptr->next; } if(key==ptr->data) { cout<<“Key Found”; return(ptr); } return NULL; }
  • 12. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 12 void display() { hash *ptr; for(i=0;i<MAX;i++) { ptr=ht[i]; while(ptr!=NULL) { cout<<ptr->prn<<“t”<<ptr->name<<“->”; ptr=ptr->next; } } }
  • 13. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 13 Delete() { int addr; node *ptr,*prev,*temp; cout<<“enter data to be deleted”; cin>>key; addr=key%MAX; prev=ptr=ht[addr]; if(ptr->data==key) { prev=prev->next; ht[addr]=prev; delete(ptr); } else { while(ptr->data!=key && ptr->next!=NULL) { prev=ptr; ptr=ptr->next; } if(ptr->data==key) { prev->next=ptr->next; delete(ptr); } }//end of else } //end of function
  • 14. • Time Complexity: Search= O(1+α ) where α is loading factor Insert/Delete: O(1+α ) DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon 14