SlideShare a Scribd company logo
1 of 21
Introduction to Hashing Techniques

Objectives
In this lesson, you will learn to:
 Randomly access data by using a hash index
 Implement Hashing function
 Define different hashing techniques
 Define collision and how collisions are handled
 Create a hash index and use it, to randomly access
  data from a file, using the key field




                       Introduction to Hashing Techniques/Lesson 8/Slide 1 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hashing
  It means converting a key to an address to retrieve a
   record.
  Given a key, the offset of the record can be calculated
   with the following formula:
      Key * Record length




                    Introduction to Hashing Techniques/Lesson 8/Slide 2 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hashing Functions
  Given a key, the hash function converts it into a hash
   value (location) within the range 1 -n, where n is the
   size of the storage (address) space that has been
   allocated for the records.
  The record is then retrieved at the location generated.
  Dividing is one of the commonly used hashing
   function.




                    Introduction to Hashing Techniques/Lesson 8/Slide 3 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hashing Techniques
  Two hashing techniques commonly employed are:
       Hash indexes
       Hash tables
  The goal of both the techniques is same, which is as
   follows:
       To identify the location of a data record in a file
        using a key, to address transformation.




                      Introduction to Hashing Techniques/Lesson 8/Slide 4 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hash Indexes
  An index created by placing keys in locations
   calculated using a hashing function is called a hash
   index file.
  It contains a key-offset pair corresponding to each
   record in the data file.
  Following two files are used in the technique
   employing hash index:
       A file containing the data records, and
       A hash index file.



                     Introduction to Hashing Techniques/Lesson 8/Slide 5 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hash Tables
  Hash tables make use of data files only.
  It involves calculation of a location based on the value
   of a key.
  In this method, a whole record is inserted into the
   calculated position in the data file, i.e. the hash table.




                     Introduction to Hashing Techniques/Lesson 8/Slide 6 of 21
  ©NIIT
Introduction to Hashing Techniques

 Collisions
  An attempt to store two keys at the same position is
   known as collision.
  It will occur irrespective of the hashing function used.




                    Introduction to Hashing Techniques/Lesson 8/Slide 7 of 21
  ©NIIT
Introduction to Hashing Techniques

  Collision Processing
  Rehashing
   This method involves using a secondary hash
    function, called a rehashed function, on the hash
    value of the key.
   The rehash function is applied successively until an
    empty position is found.




                    Introduction to Hashing Techniques/Lesson 8/Slide 8 of 21
  ©NIIT
Introduction to Hashing Techniques

 Collision Processing (Contd..)
 Chaining
  This method uses links (pointers) to resolve hash
   clashes.
  Two chaining techniques are:
       Coalesed Chaining
       Separate Chaining




                   Introduction to Hashing Techniques/Lesson 8/Slide 9 of 21
  ©NIIT
Introduction to Hashing Techniques

 Coalesed Chaining
  It completely eliminates the possibility that more than
   one collision will occur even for the same hash value.
  It requires the storage area to be divided into two
   parts:
       A prime hash area
       An overflow area




                   Introduction to Hashing Techniques/Lesson 8/Slide 10 of 21
  ©NIIT
Introduction to Hashing Techniques

 Separate Chaining
  In this method, an array of header nodes is used.
  Each element in the array is a pointer, which stores
   the address of a distinct linked list.
  Each linked list is a list of records whose keys have
   the same hash values.
  When a record has to be retrieved, the hashing
   function converts the given key to yield a position
   (subscript) in the array.




                   Introduction to Hashing Techniques/Lesson 8/Slide 11 of 21
  ©NIIT
Introduction to Hashing Techniques

 Bucket Hashing
  The hashing of a key yield the position of a storage
   area in which several key entries can be stored. This
   storage area is called a bucket.
  The file is divided into a number of such buckets.
   Each bucket has enough space to store multiple
   values.
  When a record has to be retrieved, its key is hashed
   to give an offset. This offset is a bucket offset. Then
   the bucket is read into internal memory and searched
   sequentially.



                   Introduction to Hashing Techniques/Lesson 8/Slide 12 of 21
  ©NIIT
Introduction to Hashing Techniques

 Hash Indexes Vs Hash Tables
  The choice of hashing method depends on the
   following factors:
       Data Organization
       Access Speed
       Disk Space Requirement




                   Introduction to Hashing Techniques/Lesson 8/Slide 13 of 21
  ©NIIT
Introduction to Hashing Techniques

 An Example to Illustrate the Use of A Hash Table
 The assumptions made in this example are:
         The key is an alphanumeric field, the first byte
          of which is an alphabet.
         Only one key exists for a particular hash value.
         The problem of collisions is not being
          addressed.
         The file structure assumed is shown below:
          Field         Length                Type
          city           10                   String
          Population                  2                   Integer

                   Introduction to Hashing Techniques/Lesson 8/Slide 14 of 21
  ©NIIT
Introduction to Hashing Techniques

 An Example to Illustrate the Use of A Hash Table
   (Contd..)
       The hashing algorithm used is as follows: the first
        letter from the alphabetic key is extracted and the
        position of this letter in the alphabet is used as the
        hash value. If the first letter in the key is C, then
        the hash value is 3. Thus, it is obvious that the
        number of positions (or buckets) that a key might
        hash to is 26, which is the number of letters in the
        alphabet.
  The processing required to create the hash table
   involves the following steps:
       Creating file space
                     Introduction to Hashing Techniques/Lesson 8/Slide 15 of 21
  ©NIIT
Introduction to Hashing Techniques

 An Example to Illustrate the Use of A Hash Table
   (Contd..)
       Accepting Data
       Find the correct bucket
       Writing to the hash table




                    Introduction to Hashing Techniques/Lesson 8/Slide 16 of 21
  ©NIIT
Introduction to Hashing Techniques

 Problem Statement 8.D.1
  Create a hash table for records having structure given
   below:
      Field        Size
      City         10
      Population              2
      The hashing algorithm used is as follows: the first
      letter from the alphabetic is used as the hash value. If
      the first letter in the key is C, then the hash value is
      3. Thus, it is obvious that the number of positions(or
      buckets) that a key might hash to is 26, which is the
      number of letters in the alphabet.
                        Introduction to Hashing Techniques/Lesson 8/Slide 17 of 21
  ©NIIT
Introduction to Hashing Techniques

 Problem Statement 8.D.1 (Contd..)
          only one key exists for a particular hash value. In
          other words, there is only one record per bucket.
          The problem of collisions is not being addressed.
          The key is an alphanumeric field, the first byte of
          which is an alphabet.




                       Introduction to Hashing Techniques/Lesson 8/Slide 18 of 21
  ©NIIT
Introduction to Hashing Techniques

Summary
In this lesson, you learned that:
 Hashing is a technique used to access data stored in
  files
 Using hashing techniques, it is possible to calculate
  the position of a record in a data file from its key field
  value
 The main purpose of hashing is to eliminate
  unnecessary searching by using the method of direct
  access to retrieve a record. This is done by
  transforming the key to yield the offset of the record
 An algorithm called, a hashing function, is used to
  perform the key to address transformation

                      Introduction to Hashing Techniques/Lesson 8/Slide 19 of 21
   ©NIIT
Introduction to Hashing Techniques

Summary (Contd..)
 It often happens that more than one key hashes to
  the same hash value resulting in collision. AS a result,
  an attempt is made to store two records in one
  location. Collisions are processed by using various
  algorithms, three of which are:
     Rehashing
     Linked list collision processing
     Bucket hashing




                    Introduction to Hashing Techniques/Lesson 8/Slide 20 of 21
  ©NIIT
Introduction to Hashing Techniques

Summary (Contd..)
 Several hashing strategies can be employed, two of
  which are:
    Hash indexing
    Hash tables




                     Introduction to Hashing Techniques/Lesson 8/Slide 21 of 21
    ©NIIT

More Related Content

What's hot (20)

Hashing data
Hashing dataHashing data
Hashing data
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Hashing
HashingHashing
Hashing
 
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)
 
Hash table
Hash tableHash table
Hash table
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
linear probing
linear probinglinear probing
linear probing
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
Hash Tables in data Structure
Hash Tables in data StructureHash Tables in data Structure
Hash Tables in data Structure
 
Hashing
HashingHashing
Hashing
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
Hashing
HashingHashing
Hashing
 
Hashing Algorithm
Hashing AlgorithmHashing Algorithm
Hashing Algorithm
 
Ch17 Hashing
Ch17 HashingCh17 Hashing
Ch17 Hashing
 
Hashing
HashingHashing
Hashing
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 

Viewers also liked

11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16Niit Care
 
Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09Niit Care
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20Niit Care
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13Niit Care
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01Niit Care
 
Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013MattKilner
 
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakProbabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakPyData
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19Niit Care
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_cNiit Care
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItAzul Systems Inc.
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashingJohan Tibell
 

Viewers also liked (20)

11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
 
Dacj 2-2 c
Dacj 2-2 cDacj 2-2 c
Dacj 2-2 c
 
 
Oops recap
Oops recapOops recap
Oops recap
 
Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Rdbms xp 01
Rdbms xp 01Rdbms xp 01
Rdbms xp 01
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
 
Computer
ComputerComputer
Computer
 
Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013
 
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakProbabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_c
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Dacj 1-1 a
Dacj 1-1 aDacj 1-1 a
Dacj 1-1 a
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashing
 

Similar to Ds 8

Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)Home
 
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
 
Hashing and Hash Tables
Hashing and Hash TablesHashing and Hash Tables
Hashing and Hash Tablesadil raja
 
Hashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfHashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfJaithoonBibi
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxmy6305874
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
Bloom Filters: An Introduction
Bloom Filters: An IntroductionBloom Filters: An Introduction
Bloom Filters: An IntroductionIRJET Journal
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
Implementação do Hash Coalha/Coalesced
Implementação do Hash Coalha/CoalescedImplementação do Hash Coalha/Coalesced
Implementação do Hash Coalha/CoalescedCriatividadeZeroDocs
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structureMahmoud Alfarra
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashingAkhil Prem
 
Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App IJECEIAES
 
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
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Similarity-preserving hash for content-based audio retrieval using unsupervis...
Similarity-preserving hash for content-based audio retrieval using unsupervis...Similarity-preserving hash for content-based audio retrieval using unsupervis...
Similarity-preserving hash for content-based audio retrieval using unsupervis...IJECEIAES
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing TablesChinmaya M. N
 

Similar to Ds 8 (20)

asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
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
 
Hashing and Hash Tables
Hashing and Hash TablesHashing and Hash Tables
Hashing and Hash Tables
 
Hashing
HashingHashing
Hashing
 
Hashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfHashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdf
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Bloom Filters: An Introduction
Bloom Filters: An IntroductionBloom Filters: An Introduction
Bloom Filters: An Introduction
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Implementação do Hash Coalha/Coalesced
Implementação do Hash Coalha/CoalescedImplementação do Hash Coalha/Coalesced
Implementação do Hash Coalha/Coalesced
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structure
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App
 
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
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
 
Hash pre
Hash preHash pre
Hash pre
 
Similarity-preserving hash for content-based audio retrieval using unsupervis...
Similarity-preserving hash for content-based audio retrieval using unsupervis...Similarity-preserving hash for content-based audio retrieval using unsupervis...
Similarity-preserving hash for content-based audio retrieval using unsupervis...
 
DS THEORY 35.pptx
DS THEORY 35.pptxDS THEORY 35.pptx
DS THEORY 35.pptx
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Ds 8

  • 1. Introduction to Hashing Techniques Objectives In this lesson, you will learn to: Randomly access data by using a hash index Implement Hashing function Define different hashing techniques Define collision and how collisions are handled Create a hash index and use it, to randomly access data from a file, using the key field Introduction to Hashing Techniques/Lesson 8/Slide 1 of 21 ©NIIT
  • 2. Introduction to Hashing Techniques Hashing It means converting a key to an address to retrieve a record. Given a key, the offset of the record can be calculated with the following formula: Key * Record length Introduction to Hashing Techniques/Lesson 8/Slide 2 of 21 ©NIIT
  • 3. Introduction to Hashing Techniques Hashing Functions Given a key, the hash function converts it into a hash value (location) within the range 1 -n, where n is the size of the storage (address) space that has been allocated for the records. The record is then retrieved at the location generated. Dividing is one of the commonly used hashing function. Introduction to Hashing Techniques/Lesson 8/Slide 3 of 21 ©NIIT
  • 4. Introduction to Hashing Techniques Hashing Techniques Two hashing techniques commonly employed are: Hash indexes Hash tables The goal of both the techniques is same, which is as follows: To identify the location of a data record in a file using a key, to address transformation. Introduction to Hashing Techniques/Lesson 8/Slide 4 of 21 ©NIIT
  • 5. Introduction to Hashing Techniques Hash Indexes An index created by placing keys in locations calculated using a hashing function is called a hash index file. It contains a key-offset pair corresponding to each record in the data file. Following two files are used in the technique employing hash index: A file containing the data records, and A hash index file. Introduction to Hashing Techniques/Lesson 8/Slide 5 of 21 ©NIIT
  • 6. Introduction to Hashing Techniques Hash Tables Hash tables make use of data files only. It involves calculation of a location based on the value of a key. In this method, a whole record is inserted into the calculated position in the data file, i.e. the hash table. Introduction to Hashing Techniques/Lesson 8/Slide 6 of 21 ©NIIT
  • 7. Introduction to Hashing Techniques Collisions An attempt to store two keys at the same position is known as collision. It will occur irrespective of the hashing function used. Introduction to Hashing Techniques/Lesson 8/Slide 7 of 21 ©NIIT
  • 8. Introduction to Hashing Techniques Collision Processing Rehashing This method involves using a secondary hash function, called a rehashed function, on the hash value of the key. The rehash function is applied successively until an empty position is found. Introduction to Hashing Techniques/Lesson 8/Slide 8 of 21 ©NIIT
  • 9. Introduction to Hashing Techniques Collision Processing (Contd..) Chaining This method uses links (pointers) to resolve hash clashes. Two chaining techniques are: Coalesed Chaining Separate Chaining Introduction to Hashing Techniques/Lesson 8/Slide 9 of 21 ©NIIT
  • 10. Introduction to Hashing Techniques Coalesed Chaining It completely eliminates the possibility that more than one collision will occur even for the same hash value. It requires the storage area to be divided into two parts: A prime hash area An overflow area Introduction to Hashing Techniques/Lesson 8/Slide 10 of 21 ©NIIT
  • 11. Introduction to Hashing Techniques Separate Chaining In this method, an array of header nodes is used. Each element in the array is a pointer, which stores the address of a distinct linked list. Each linked list is a list of records whose keys have the same hash values. When a record has to be retrieved, the hashing function converts the given key to yield a position (subscript) in the array. Introduction to Hashing Techniques/Lesson 8/Slide 11 of 21 ©NIIT
  • 12. Introduction to Hashing Techniques Bucket Hashing The hashing of a key yield the position of a storage area in which several key entries can be stored. This storage area is called a bucket. The file is divided into a number of such buckets. Each bucket has enough space to store multiple values. When a record has to be retrieved, its key is hashed to give an offset. This offset is a bucket offset. Then the bucket is read into internal memory and searched sequentially. Introduction to Hashing Techniques/Lesson 8/Slide 12 of 21 ©NIIT
  • 13. Introduction to Hashing Techniques Hash Indexes Vs Hash Tables The choice of hashing method depends on the following factors: Data Organization Access Speed Disk Space Requirement Introduction to Hashing Techniques/Lesson 8/Slide 13 of 21 ©NIIT
  • 14. Introduction to Hashing Techniques An Example to Illustrate the Use of A Hash Table The assumptions made in this example are: The key is an alphanumeric field, the first byte of which is an alphabet. Only one key exists for a particular hash value. The problem of collisions is not being addressed. The file structure assumed is shown below: Field Length Type city 10 String Population 2 Integer Introduction to Hashing Techniques/Lesson 8/Slide 14 of 21 ©NIIT
  • 15. Introduction to Hashing Techniques An Example to Illustrate the Use of A Hash Table (Contd..) The hashing algorithm used is as follows: the first letter from the alphabetic key is extracted and the position of this letter in the alphabet is used as the hash value. If the first letter in the key is C, then the hash value is 3. Thus, it is obvious that the number of positions (or buckets) that a key might hash to is 26, which is the number of letters in the alphabet. The processing required to create the hash table involves the following steps: Creating file space Introduction to Hashing Techniques/Lesson 8/Slide 15 of 21 ©NIIT
  • 16. Introduction to Hashing Techniques An Example to Illustrate the Use of A Hash Table (Contd..) Accepting Data Find the correct bucket Writing to the hash table Introduction to Hashing Techniques/Lesson 8/Slide 16 of 21 ©NIIT
  • 17. Introduction to Hashing Techniques Problem Statement 8.D.1 Create a hash table for records having structure given below: Field Size City 10 Population 2 The hashing algorithm used is as follows: the first letter from the alphabetic is used as the hash value. If the first letter in the key is C, then the hash value is 3. Thus, it is obvious that the number of positions(or buckets) that a key might hash to is 26, which is the number of letters in the alphabet. Introduction to Hashing Techniques/Lesson 8/Slide 17 of 21 ©NIIT
  • 18. Introduction to Hashing Techniques Problem Statement 8.D.1 (Contd..) only one key exists for a particular hash value. In other words, there is only one record per bucket. The problem of collisions is not being addressed. The key is an alphanumeric field, the first byte of which is an alphabet. Introduction to Hashing Techniques/Lesson 8/Slide 18 of 21 ©NIIT
  • 19. Introduction to Hashing Techniques Summary In this lesson, you learned that: Hashing is a technique used to access data stored in files Using hashing techniques, it is possible to calculate the position of a record in a data file from its key field value The main purpose of hashing is to eliminate unnecessary searching by using the method of direct access to retrieve a record. This is done by transforming the key to yield the offset of the record An algorithm called, a hashing function, is used to perform the key to address transformation Introduction to Hashing Techniques/Lesson 8/Slide 19 of 21 ©NIIT
  • 20. Introduction to Hashing Techniques Summary (Contd..) It often happens that more than one key hashes to the same hash value resulting in collision. AS a result, an attempt is made to store two records in one location. Collisions are processed by using various algorithms, three of which are: Rehashing Linked list collision processing Bucket hashing Introduction to Hashing Techniques/Lesson 8/Slide 20 of 21 ©NIIT
  • 21. Introduction to Hashing Techniques Summary (Contd..) Several hashing strategies can be employed, two of which are: Hash indexing Hash tables Introduction to Hashing Techniques/Lesson 8/Slide 21 of 21 ©NIIT

Editor's Notes

  1. Lower Bound and Upper Bound to denote the first element number and the last element number respectively
  2. Lower Bound and Upper Bound to denote the first element number and the last element number respectively