際際滷

際際滷Share a Scribd company logo
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.
Hash pre
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.
Hash pre
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
integerASCLL 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
Ad

Recommended

Hashing
Hashing
LavanyaJ28
Indexing
Indexing
myrajendra
Ch17 Hashing
Ch17 Hashing
leminhvuong
Intro To TSQL - Unit 5
Intro To TSQL - Unit 5
iccma
Unit viii searching and hashing
Unit viii searching and hashing
Tribhuvan University
Data indexing presentation
Data indexing presentation
gmbmanikandan
4.4 hashing02
4.4 hashing02
Krish_ver2
Overview of Storage and Indexing ...
Overview of Storage and Indexing ...
Javed Khan
Database index
Database index
Riteshkiit
Quick And Dirty Databases
Quick And Dirty Databases
cwarren
Indexing techniques
Indexing techniques
Huda Alameen
Data Structure
Data Structure
HarshGupta663
Data storage and indexing
Data storage and indexing
pradeepa velmurugan
Apex collection patterns
Apex collection patterns
Sathishkumar Periyasamy
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
rainynovember12
Html tables
Html tables
Sikandar Pandit
Rdbms terminology
Rdbms terminology
Harish Gyanani
What is Link list? explained with animations
What is Link list? explained with animations
PratikNaik41
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
AminaRepo
Hash table in java
Hash table in java
siriindian
Intro to tsql unit 5
Intro to tsql unit 5
Syed Asrarali
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
Steve Johnson
File Organization in Database
File Organization in Database
A. S. M. Shafi
Chapter 12 ds
Chapter 12 ds
Hanif Durad
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
Data Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, Collision
sailaja156145
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
Hashing and Collision Advanced data structure and algorithm
Hashing and Collision Advanced data structure and algorithm
yogoso2948
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711

More Related Content

What's hot (15)

Database index
Database index
Riteshkiit
Quick And Dirty Databases
Quick And Dirty Databases
cwarren
Indexing techniques
Indexing techniques
Huda Alameen
Data Structure
Data Structure
HarshGupta663
Data storage and indexing
Data storage and indexing
pradeepa velmurugan
Apex collection patterns
Apex collection patterns
Sathishkumar Periyasamy
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
rainynovember12
Html tables
Html tables
Sikandar Pandit
Rdbms terminology
Rdbms terminology
Harish Gyanani
What is Link list? explained with animations
What is Link list? explained with animations
PratikNaik41
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
AminaRepo
Hash table in java
Hash table in java
siriindian
Intro to tsql unit 5
Intro to tsql unit 5
Syed Asrarali
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
Steve Johnson
File Organization in Database
File Organization in Database
A. S. M. Shafi
Database index
Database index
Riteshkiit
Quick And Dirty Databases
Quick And Dirty Databases
cwarren
Indexing techniques
Indexing techniques
Huda Alameen
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
rainynovember12
What is Link list? explained with animations
What is Link list? explained with animations
PratikNaik41
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
AminaRepo
Hash table in java
Hash table in java
siriindian
Intro to tsql unit 5
Intro to tsql unit 5
Syed Asrarali
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
Steve Johnson
File Organization in Database
File Organization in Database
A. S. M. Shafi

Similar to Hash pre (20)

Chapter 12 ds
Chapter 12 ds
Hanif Durad
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
Data Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, Collision
sailaja156145
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
Hashing and Collision Advanced data structure and algorithm
Hashing and Collision Advanced data structure and algorithm
yogoso2948
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
Hashing
Hashing
Dawood Faheem Abbasi
08 Hash Tables
08 Hash Tables
Andres Mendez-Vazquez
Hashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
Algorithms notes tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
Hashing And Hashing Tables
Hashing And Hashing Tables
Chinmaya M. N
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
asdfew.pptx
asdfew.pptx
hunterkurosaki
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
Hashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of Algorithms
KavitaSingh962656
Data Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
Hash based inventory system
Hash based inventory system
DADITIRUMALATARUN
Presentation.pptx
Presentation.pptx
AgonySingh
Chapter 12 ds
Chapter 12 ds
Hanif Durad
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
Data Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, Collision
sailaja156145
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
Hashing and Collision Advanced data structure and algorithm
Hashing and Collision Advanced data structure and algorithm
yogoso2948
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
Hashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
Algorithms notes tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
Hashing And Hashing Tables
Hashing And Hashing Tables
Chinmaya M. N
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
Hashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of Algorithms
KavitaSingh962656
Data Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
Hash based inventory system
Hash based inventory system
DADITIRUMALATARUN
Presentation.pptx
Presentation.pptx
AgonySingh
Ad

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.
  • 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.
  • 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 integerASCLL 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