SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
Tafelia Technical
   university
      TTU
*Hash table or hash map is a data
structure that uses a hash function to
map identifying values, known as
keys(e.g., a person's name), to their
associated values (e.g., their telephone
number).
*The hash function is used to transform
                             hash)
the key into the index (the hash) of an
array element (the slot or bucket) where
                           bucket)
the corresponding value is to be sought.
Ideally, the hash function should map each
possible key to a unique slot index, but this ideal
is rarely achievable in practice (unless the hash
keys are fixed .
HASH TABLE TYPES
  There are two types of Hash Tables: Open-addressed Hash Tables and Separate-
                                      Open-                          Separate-
                Tables.
  Chained Hash Tables
  An Open-addressed Hash Table is a one-dimensional array indexed by
     Open-
  integer values that are computed by an index function called a hash function
                                                                      function.
  A Separate-Chained Hash Table is a one-dimensional array of linked lists indexed by
    Separate-
  integer values that are computed by an index function called a hash function
                                                                      function.
  Hash tables are sometimes referred to as scatter tables
                                                   tables.”chain”.
  Typical hash table operations are:

          Initialization.
        — Initialization.
        — Insertion.
          Insertion.
        — Searching
          Deletion.
        — Deletion.
Separate chained hash table
• Linked list at each table location
• The table entries are pointers to list
heads
There are two types of hashing :
1. Static hashing: In static hashing, the hash function
maps search-key values to a fixed set of locations.
 2. Dynamic hashing: In dynamic hashing a hash table
can grow to handle more items. The associated hash
function must change as the table grows.

The load factor of a hash table is the ratio of the number of
keys in the table to the size of the hash table.

 The higher the load factor, the slower the retrieval.

  With open addressing, the load factor cannot exceed 1. With chaining, the load
 factor often exceeds 1.
hash function
  f:
index = f(key, arrayLength) The hash function calculates
  an index within the array from the data key.
  arrayLength is the size of the array. For assembly
  language or other low-level programs, a trivial hash
  function can often create an index with just one or two
  inline machine instructions
A hash function h, is a function which transforms a
        function,
key from a set, K, into an index in a table of size n:
              h: K -> {0, 1, ..., n-2, n-1}
                       {0         n- n-
A key can be a number, a string, a record etc.
The size of the set of keys, |K| to be relatively very
                              |K|,
large.
It is possible for different keys to hash to the same
array location.
This situation is called collision and the colliding keys
are called synonyms.
A good hash function should:

    — Minimize collisions.

    — Be easy and quick to compute.

    — Distribute key values evenly in the hash table.

    — Use all the information provided in the key.
1.   Division Remainder (using the table size as the divisor)

Computes hash value from key using the % operator.

Table size that is a power of 2 like 32 and 1024 should be avoided,
for it leads to more collisions.
Prime numbers not close to powers of 2 are better table size values.

h(key) = key mod size
(remainder of key divided by size)
where size is the table size m
2. Folding

It involves splitting keys into two or more parts and then
combining the parts to form the hash addresses.
To map the key 25936715 to a range between 0 and 9999, we
can:
     — split the number into two as 2593 and 6715 and
     — add these two to obtain 9308 as the hash value.
Very useful if we have keys that are very large.
A great advantage is ability to transform non-integer keys into
integer values.
2. Truncation or Digit/Character Extraction

Works based on the distribution of digits or
characters in the key.
If search key is string we first convert it to
integer”ASCLL” then use hash table
H(“note”)=78+79+84+69
Advantages
The main advantage of hash tables
over other table data structures is
speed. This advantage is more
apparent when the number of entries
is large (thousands or more.
HASH TABLE APPLICATIONS
Database systems
Symbol tables The tables used by compilers to maintain information
       tables:
about symbols from a program.

Data dictionaries Data structures that support adding, deleting, and
      dictionaries:
searching for data. Although the operations of a hash table and a data
dictionary are similar, other data structures may be used to implement
data dictionaries. Using a hash table is particularly efficient.

Network processing algorithms Hash tables are fundamental
                    algorithms:
components of several network processing algorithms and applications,
including route lookup, packet classification, and network monitoring.
EXAMPLE
Suppose that we want to store 10,000 students records
(each with a 5-digit ID) in a given containerThe id
field in this class can be used as a search key for
records in the container.



      class StudentRecord {
         String name;    // Student name
         double height; // Student height
         long id;        // Unique id
      }
Example 1: Introduction to Hashing
Name                                         ID        h(r) = id % 13
Al-Otaibi, Ziyad                           985926            6
Al-Turki, Musab Ahmad Bakeer               970876            10
Al-Saegh, Radha Mahdi                      980962            8
Al-Shahrani, Adel Saad                     986074            11
Al-Awami, Louai Adnan Muhammad             970728            5
Al-Amer, Yousuf Jauwad                     994593            2
Al-Helal, Husain Ali AbdulMohsen           996321            1

0      1   2       3   4   5   6   7   8    9     10    11    12

Weitere ähnliche Inhalte

Was ist angesagt?

Database index
Database indexDatabase index
Database indexRiteshkiit
 
Quick And Dirty Databases
Quick And Dirty DatabasesQuick And Dirty Databases
Quick And Dirty Databasescwarren
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniquesHuda Alameen
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
What is Link list? explained with animations
What is Link list? explained with animationsWhat is Link list? explained with animations
What is Link list? explained with animationsPratikNaik41
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & PreparationAminaRepo
 
Hash table in java
Hash table in javaHash table in java
Hash table in javasiriindian
 
Intro to tsql unit 5
Intro to tsql   unit 5Intro to tsql   unit 5
Intro to tsql unit 5Syed Asrarali
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetSteve Johnson
 
File Organization in Database
File Organization in DatabaseFile Organization in Database
File Organization in DatabaseA. S. M. Shafi
 

Was ist angesagt? (15)

Database index
Database indexDatabase index
Database index
 
Quick And Dirty Databases
Quick And Dirty DatabasesQuick And Dirty Databases
Quick And Dirty Databases
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniques
 
Data Structure
Data StructureData Structure
Data Structure
 
Data storage and indexing
Data storage and indexingData storage and indexing
Data storage and indexing
 
Apex collection patterns
Apex collection patternsApex collection patterns
Apex collection patterns
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
Html tables
Html tablesHtml tables
Html tables
 
Rdbms terminology
Rdbms terminologyRdbms terminology
Rdbms terminology
 
What is Link list? explained with animations
What is Link list? explained with animationsWhat is Link list? explained with animations
What is Link list? explained with animations
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
 
Hash table in java
Hash table in javaHash table in java
Hash table in java
 
Intro to tsql unit 5
Intro to tsql   unit 5Intro to tsql   unit 5
Intro to tsql unit 5
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
 
File Organization in Database
File Organization in DatabaseFile Organization in Database
File Organization in Database
 

Ähnlich wie Hash pre

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
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
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_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithmfarhankhan89766
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashingAkhil Prem
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing TablesChinmaya M. N
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11Bianca Teşilă
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structureMahmoud Alfarra
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniyaTutorialsDuniya.com
 
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...NaveenPeter8
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashingchidabdu
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingHaripritha
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on lineMilind Patil
 

Ähnlich wie Hash pre (20)

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
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
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_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
 
Hashing
HashingHashing
Hashing
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structure
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
DS THEORY 35.pptx
DS THEORY 35.pptxDS THEORY 35.pptx
DS THEORY 35.pptx
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
 
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
 

Hash pre

  • 1. Tafelia Technical university TTU
  • 2. *Hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys(e.g., a person's name), to their associated values (e.g., their telephone number). *The hash function is used to transform hash) the key into the index (the hash) of an array element (the slot or bucket) where bucket) the corresponding value is to be sought.
  • 3.
  • 4. Ideally, the hash function should map each possible key to a unique slot index, but this ideal is rarely achievable in practice (unless the hash keys are fixed .
  • 5. HASH TABLE TYPES There are two types of Hash Tables: Open-addressed Hash Tables and Separate- Open- Separate- Tables. Chained Hash Tables An Open-addressed Hash Table is a one-dimensional array indexed by Open- integer values that are computed by an index function called a hash function function. A Separate-Chained Hash Table is a one-dimensional array of linked lists indexed by Separate- integer values that are computed by an index function called a hash function function. Hash tables are sometimes referred to as scatter tables tables.”chain”. Typical hash table operations are: Initialization. — Initialization. — Insertion. Insertion. — Searching Deletion. — Deletion.
  • 6. Separate chained hash table • Linked list at each table location • The table entries are pointers to list heads
  • 7. There are two types of hashing : 1. Static hashing: In static hashing, the hash function maps search-key values to a fixed set of locations. 2. Dynamic hashing: In dynamic hashing a hash table can grow to handle more items. The associated hash function must change as the table grows. The load factor of a hash table is the ratio of the number of keys in the table to the size of the hash table. The higher the load factor, the slower the retrieval. With open addressing, the load factor cannot exceed 1. With chaining, the load factor often exceeds 1.
  • 8. hash function f: index = f(key, arrayLength) The hash function calculates an index within the array from the data key. arrayLength is the size of the array. For assembly language or other low-level programs, a trivial hash function can often create an index with just one or two inline machine instructions
  • 9. A hash function h, is a function which transforms a function, key from a set, K, into an index in a table of size n: h: K -> {0, 1, ..., n-2, n-1} {0 n- n- A key can be a number, a string, a record etc. The size of the set of keys, |K| to be relatively very |K|, large. It is possible for different keys to hash to the same array location. This situation is called collision and the colliding keys are called synonyms.
  • 10. A good hash function should: — Minimize collisions. — Be easy and quick to compute. — Distribute key values evenly in the hash table. — Use all the information provided in the key.
  • 11.
  • 12. 1. Division Remainder (using the table size as the divisor) Computes hash value from key using the % operator. Table size that is a power of 2 like 32 and 1024 should be avoided, for it leads to more collisions. Prime numbers not close to powers of 2 are better table size values. h(key) = key mod size (remainder of key divided by size) where size is the table size m
  • 13. 2. Folding It involves splitting keys into two or more parts and then combining the parts to form the hash addresses. To map the key 25936715 to a range between 0 and 9999, we can: — split the number into two as 2593 and 6715 and — add these two to obtain 9308 as the hash value. Very useful if we have keys that are very large. A great advantage is ability to transform non-integer keys into integer values.
  • 14. 2. Truncation or Digit/Character Extraction Works based on the distribution of digits or characters in the key. If search key is string we first convert it to integer”ASCLL” then use hash table H(“note”)=78+79+84+69
  • 15. Advantages The main advantage of hash tables over other table data structures is speed. This advantage is more apparent when the number of entries is large (thousands or more.
  • 16. HASH TABLE APPLICATIONS Database systems Symbol tables The tables used by compilers to maintain information tables: about symbols from a program. Data dictionaries Data structures that support adding, deleting, and dictionaries: searching for data. Although the operations of a hash table and a data dictionary are similar, other data structures may be used to implement data dictionaries. Using a hash table is particularly efficient. Network processing algorithms Hash tables are fundamental algorithms: components of several network processing algorithms and applications, including route lookup, packet classification, and network monitoring.
  • 17. EXAMPLE Suppose that we want to store 10,000 students records (each with a 5-digit ID) in a given containerThe id field in this class can be used as a search key for records in the container. class StudentRecord { String name; // Student name double height; // Student height long id; // Unique id }
  • 18. Example 1: Introduction to Hashing Name ID h(r) = id % 13 Al-Otaibi, Ziyad 985926 6 Al-Turki, Musab Ahmad Bakeer 970876 10 Al-Saegh, Radha Mahdi 980962 8 Al-Shahrani, Adel Saad 986074 11 Al-Awami, Louai Adnan Muhammad 970728 5 Al-Amer, Yousuf Jauwad 994593 2 Al-Helal, Husain Ali AbdulMohsen 996321 1 0 1 2 3 4 5 6 7 8 9 10 11 12