Dshash
Dshash
Syllabus: Hashing - Perfect hashing functions. Hash table, Hash Functions, Operations, Hash collision,
Application.
Hashing
Hashing is a technique used in data structures that efficiently stores and retrieves data in a way that
allows for quick access.
Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash
function. It enables fast retrieval of information based on its key.
The great thing about hashing is, we can achieve all three operations (search, insert and delete) in
O(1) time on average.
Hashing is mainly used to implement a set of distinct items (only keys) and dictionaries (key value
pairs).
Components of Hashing
There are majorly three components of hashing:
Key: A Key can be anything string or integer which is fed as input in the hash function the
technique that determines an index or location for storage of an item in a data structure.
Hash Function: Receives the input key and returns the index of an element in an array called a hash
table. The index is known as the hash index.
Hash Table: Hash table is typically an array of lists. It stores values corresponding to the keys. Hash
stores the data in an associative manner in an array where each data value has its own unique index.
Hash Table
A Hash table is defined as a data structure used to insert, look up, and remove key-value pairs quickly. It
operates on the hashing concept, where each key is translated by a hash function into a distinct index in an
array. The index functions as a storage location for the matching value. In simple words, it maps the keys
with the value.
Hash Function
Hash functions are a fundamental concept in computer science and play a crucial role in various
applications such as data storage, retrieval, and cryptography.
A hash function creates a mapping from an input key to an index in hash table.
Properties,
a. Deterministic: A hash function must consistently produce the same output for the same input.
Applications
Hashing provides constant time search, insert and delete operations on average. This is why hashing is one
of the most used data structure, example problems are, distinct elements, counting frequencies of items,
finding duplicates, etc.
There are many other applications of hashing, including modern day cryptography hash functions. Some of
these applications are listed below:
Message Digest : This is an application of cryptographic Hash Functions
Password Verification : Cryptographic hash functions are very commonly used in password
verification.
Data Structures(Programming Languages) : Various programming languages have hash table-based
Data Structures. The basic idea is to create a key-value pair where key is supposed to be a unique
value, whereas value can be same for different keys.
Compiler Operation : To differentiate between the keywords of a programming language(if, else,
for, return etc.) and other identifiers and to successfully compile the program, the compiler stores
all these keywords in a set which is implemented using a hash table.
Rabin-Karp Algorithm : This is basically a string-searching algorithm which uses hashing to find
any one set of patterns in a string.
QUESTIONS
1. Define hashing, hash table, hash collision, hash function
2. List the properties of hash function.
3. Explain components of hashing.
4. List & explain applications of hashing.
5. Code
6. Compare open addressing methods.