SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

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

Notes de l'éditeur

  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