SlideShare una empresa de Scribd logo
1 de 21
HASH TABLE
VU QUANG TRAN
EXAMPLE
• Design a system to store employees' information using their phone number as
key
• Operations: Insert, Search, Delete
• Some possible data structures:
• Array
• Linked List
• Balanced Binary Search Tree
• Direct Access Table
EXAMPLE
• Design a system to store employees' information using their phone number as
key
• Operations: Insert, Search, Delete
• Some possible data structures:
• Array: O(n) Search, Delete
• Linked List: O(n) Search
• Balanced Binary Search Tree: O(log n) All
• Direct Access Table: Space Wastage
=> Hash Table: O(1) All
BASICS
• Data Structure that implements Associative
Array
• Map key to corresponding value
• Use Hash function to compute index of key-
value pairs into an array of buckets
• O(1) complexity on average and O(n) in worst
case
HASHING
• Distribute the entries (key-value pairs) across an array of buckets
• Hash function: Map data of arbitrary size to data of fixed size
• Two steps:
1. hash = hash_func(key)
2. index = hash % table_size
CHOOSING A HASH FUNCTION
• Easy to compute
• Uniform Distribution
TYPES OF HASH FUNCTION
• Two types:
• Cryptographic hash
• Non-cryptographic hash
• Non-cryptographic hash provides weaker
guarantees than cryptographic hash in
exchange for performance improvements
• Example:
• Crypto: BLAKE2b, SHA-512, MD5, …
• Non-crypto: MurmurHash, xxHash, ...
• Cryptographic hash aims to provide
certain security guarantees
• Main properties of cryptographic hash:
• Deterministic
• Quick
• One-way function
• Avalanche effect
• Collision resistant
• Pre-image attack resistant
COLLISION RESOLUTION
• Two or more keys result in a same hash value
• Practically unavoidable
• Handling techniques:
• Separate chaining
• Open addressing
COLLISION RESOLUTION
SEPARATE CHAINING
• Make each cell of hash table point to a linked list of records that have same hash
function value
COLLISION RESOLUTION
SEPARATE CHAINING
• Make each cell of hash table point to a linked list of records that have same hash
function value
• Advantages:
• Simple to implement
• Hash table never fills up
• Disadvantages:
• Cache performance
• Space wastage
• Search time can become O(n) if chain
gets long
COLLISION RESOLUTION
OPEN ADDRESSING
• All elements are stored in the hash table itself
• Operations:
• Insert: Keep probing until an empty slot is found
• Search: Keep probing until key is found or an empty slot is reached
• Delete: If we simply delete a key, then search may fail. So slots of deleted keys are
marked specially as DELETED
COLLISION RESOLUTION
OPEN ADDRESSING
Types:
• Linear probing: Linearly probe for next slot
index = [hash(x) + i] % S
COLLISION RESOLUTION
OPEN ADDRESSING
Types:
• Linear probing: Linearly probe for next slot => Clustering
index = [hash(x) + i] % S
COLLISION RESOLUTION
OPEN ADDRESSING
Types:
• Linear probing: Linearly probe for next slot => Clustering
index = [hash(x) + i] % S
• Quadratic probing: Look for i^2 slot in ith iteration
index = [hash(x) + i^2] % S
COLLISION RESOLUTION
OPEN ADDRESSING
Types:
• Linear probing: Linearly probe for next slot => Clustering
index = [hash(x) + i] % S
• Quadratic probing: Look for i^2 slot in ith iteration
index = [hash(x) + i^2] % S
• Double hashing: Use another hash function hash2(x) and look for i*hash2(x) in ith
iteration
index = [hash(x) + i*hash2(x)] % S
COLLISION RESOLUTION
OPEN ADDRESSING
Comparison:
• Linear probing:
• Easy to compute
• Best cache performance
• Suffers from Clustering
• Quadratic probing:
• Lies between cache performance and clustering
• Double hashing:
• Poor cache performance
• No clustering
• More computation time
COLLISION RESOLUTION
OPEN ADDRESSING
• Advantages:
• Better cache performance
• Better space usage
• Disadvantages:
• Harder to implement
• Hash table may become full
• Clustering
DYNAMIC RESIZING
• Load factor = number of entries / number of buckets
• When load factor is too low or too high => Dynamic resizing
• Approaches:
• Complete resizing
• Incremental resizing
USAGE
• Associative Array
• Database Indexing
• Cache
• Set
• …
REFERENCE
• Wikipedia
• GeeksForGeeks
THANK YOU

Más contenido relacionado

La actualidad más candente

Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary searchNisha Soms
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal Shah
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structuresDurgaDeviCbit
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTSoumen Santra
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure Meghaj Mallick
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 

La actualidad más candente (20)

Array data structure
Array data structureArray data structure
Array data structure
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Sorting
SortingSorting
Sorting
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Circular queue
Circular queueCircular queue
Circular queue
 
Stack
StackStack
Stack
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Red black tree
Red black treeRed black tree
Red black tree
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 

Similar a Hash table

Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT icajiwol341
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing TablesChinmaya M. N
 
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
 
Hash presentation
Hash presentationHash presentation
Hash presentationomercode
 
Hash Functions FTW
Hash Functions FTWHash Functions FTW
Hash Functions FTWsunnygleason
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
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
 
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
 

Similar a Hash table (20)

Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
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
 
Hashing
HashingHashing
Hashing
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hash presentation
Hash presentationHash presentation
Hash presentation
 
Hash Functions FTW
Hash Functions FTWHash Functions FTW
Hash Functions FTW
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
 
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
 
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
 
Hash function
Hash functionHash function
Hash function
 
session 15 hashing.pptx
session 15   hashing.pptxsession 15   hashing.pptx
session 15 hashing.pptx
 

Último

Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Thomas Poetter
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Boston Institute of Analytics
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataTecnoIncentive
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data VisualizationKianJazayeri1
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024Susanna-Assunta Sansone
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxaleedritatuxx
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Decoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectDecoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectBoston Institute of Analytics
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhh
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhhThiophen Mechanism khhjjjjjjjhhhhhhhhhhh
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhhYasamin16
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesTimothy Spann
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 

Último (20)

Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded data
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data Visualization
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
Decoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectDecoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis Project
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhh
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhhThiophen Mechanism khhjjjjjjjhhhhhhhhhhh
Thiophen Mechanism khhjjjjjjjhhhhhhhhhhh
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 

Hash table

  • 2. EXAMPLE • Design a system to store employees' information using their phone number as key • Operations: Insert, Search, Delete • Some possible data structures: • Array • Linked List • Balanced Binary Search Tree • Direct Access Table
  • 3. EXAMPLE • Design a system to store employees' information using their phone number as key • Operations: Insert, Search, Delete • Some possible data structures: • Array: O(n) Search, Delete • Linked List: O(n) Search • Balanced Binary Search Tree: O(log n) All • Direct Access Table: Space Wastage => Hash Table: O(1) All
  • 4. BASICS • Data Structure that implements Associative Array • Map key to corresponding value • Use Hash function to compute index of key- value pairs into an array of buckets • O(1) complexity on average and O(n) in worst case
  • 5. HASHING • Distribute the entries (key-value pairs) across an array of buckets • Hash function: Map data of arbitrary size to data of fixed size • Two steps: 1. hash = hash_func(key) 2. index = hash % table_size
  • 6. CHOOSING A HASH FUNCTION • Easy to compute • Uniform Distribution
  • 7. TYPES OF HASH FUNCTION • Two types: • Cryptographic hash • Non-cryptographic hash • Non-cryptographic hash provides weaker guarantees than cryptographic hash in exchange for performance improvements • Example: • Crypto: BLAKE2b, SHA-512, MD5, … • Non-crypto: MurmurHash, xxHash, ... • Cryptographic hash aims to provide certain security guarantees • Main properties of cryptographic hash: • Deterministic • Quick • One-way function • Avalanche effect • Collision resistant • Pre-image attack resistant
  • 8. COLLISION RESOLUTION • Two or more keys result in a same hash value • Practically unavoidable • Handling techniques: • Separate chaining • Open addressing
  • 9. COLLISION RESOLUTION SEPARATE CHAINING • Make each cell of hash table point to a linked list of records that have same hash function value
  • 10. COLLISION RESOLUTION SEPARATE CHAINING • Make each cell of hash table point to a linked list of records that have same hash function value • Advantages: • Simple to implement • Hash table never fills up • Disadvantages: • Cache performance • Space wastage • Search time can become O(n) if chain gets long
  • 11. COLLISION RESOLUTION OPEN ADDRESSING • All elements are stored in the hash table itself • Operations: • Insert: Keep probing until an empty slot is found • Search: Keep probing until key is found or an empty slot is reached • Delete: If we simply delete a key, then search may fail. So slots of deleted keys are marked specially as DELETED
  • 12. COLLISION RESOLUTION OPEN ADDRESSING Types: • Linear probing: Linearly probe for next slot index = [hash(x) + i] % S
  • 13. COLLISION RESOLUTION OPEN ADDRESSING Types: • Linear probing: Linearly probe for next slot => Clustering index = [hash(x) + i] % S
  • 14. COLLISION RESOLUTION OPEN ADDRESSING Types: • Linear probing: Linearly probe for next slot => Clustering index = [hash(x) + i] % S • Quadratic probing: Look for i^2 slot in ith iteration index = [hash(x) + i^2] % S
  • 15. COLLISION RESOLUTION OPEN ADDRESSING Types: • Linear probing: Linearly probe for next slot => Clustering index = [hash(x) + i] % S • Quadratic probing: Look for i^2 slot in ith iteration index = [hash(x) + i^2] % S • Double hashing: Use another hash function hash2(x) and look for i*hash2(x) in ith iteration index = [hash(x) + i*hash2(x)] % S
  • 16. COLLISION RESOLUTION OPEN ADDRESSING Comparison: • Linear probing: • Easy to compute • Best cache performance • Suffers from Clustering • Quadratic probing: • Lies between cache performance and clustering • Double hashing: • Poor cache performance • No clustering • More computation time
  • 17. COLLISION RESOLUTION OPEN ADDRESSING • Advantages: • Better cache performance • Better space usage • Disadvantages: • Harder to implement • Hash table may become full • Clustering
  • 18. DYNAMIC RESIZING • Load factor = number of entries / number of buckets • When load factor is too low or too high => Dynamic resizing • Approaches: • Complete resizing • Incremental resizing
  • 19. USAGE • Associative Array • Database Indexing • Cache • Set • …

Notas del editor

  1. Associative Array is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection.
  2. Collision occurs when a newly inserted key maps to an already occupied slot in hash table
  3. Example: Hash function = key % 7
  4. Space wastage: some buckets may never be used, extra space to store links
  5. At any point, size of table must be greater than or equal to total number of keys Insert can insert an item in a deleted slot, but search doesn’t stop at a deleted slot.
  6. Example: Hash function = key % 7
  7. Clustering: Many consecutive elements form groups and it starts taking time to find a free slot or to search an element
  8. Better space usage: bucket co the luu key cua bucket khac neu co collision, no extra space for links
  9. During the resize, allocate the new hash table, but keep the old table unchanged. In each lookup or delete operation, check both tables. Perform insertion operations only in the new table. At each insertion also move r elements from the old table to the new table. When all elements are removed from the old table, deallocate it.