0% found this document useful (0 votes)
4 views1 page

If you observe carefully, in a bala

Hashing allows for faster data operations such as search, insert, and delete with an average time complexity of O(1), compared to O(logn) in balanced binary search trees. It involves using a hash function to map input data to a fixed-size string, and collision handling techniques like chaining and open addressing are necessary to manage instances where multiple keys hash to the same value. While hashing offers efficiency, it lacks the ordered structure of binary search trees and can involve complex hash function generation.

Uploaded by

Gauri Solankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

If you observe carefully, in a bala

Hashing allows for faster data operations such as search, insert, and delete with an average time complexity of O(1), compared to O(logn) in balanced binary search trees. It involves using a hash function to map input data to a fixed-size string, and collision handling techniques like chaining and open addressing are necessary to manage instances where multiple keys hash to the same value. While hashing offers efficiency, it lacks the ordered structure of binary search trees and can involve complex hash function generation.

Uploaded by

Gauri Solankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

NOTES 33

If you observe carefully, in a balanced binary search tree, if we try to search ,


insert or delete any element then the time complexity for the same is O(logn). Now
there might be a situation when our applications want to do the same operations in
a faster way i.e. in a more optimized way and here hashing comes into play. In
hashing, all the above operations can be performed in O(1) i.e. constant time. It
is important to understand that the worst case time complexity for hashing remains
O(n) but the average case time complexity is O(1).

A hash function is a function that takes an input (or “message”) and returns a
fixed-size string of characters, which is typically a “digest” that is unique to
the unique values of the input.

Statergic reduction is simply relates to work and palpalable reasoning.

An array that stores pointers to records corresponding to a given phone number. An


entry in hash table is NIL if no existing phone number has hash function value
equal to the index for the entry. In simple terms, we can say that hash table is a
generalization of array. Hash table gives the functionality in which a collection
of data is stored in such a way that it is easy to find those items later if
required. This makes searching of an element very efficient.

Collision H
andling: Since a hash function gets us a small number for a key which is a big
integer or string, there is the possibility that two keys result in the same value.
The situation where a newly inserted key maps to an already occupied slot in the
hash table is called collision and must be handled using some collision handling
technique. Following are the ways to handle collisions:
Chaining: The idea is to make each cell of the hash table point to a linked list of
records that have the same hash function value. Chaining is simple but requires
additional memory outside the table.
Open Addressing: In open addressing, all elements are stored in the hash table
itself. Each table entry contains either a record or NIL. When searching for an
element, we one by one examine table slots until the desired element is found or it
is clear that the element is not in the table.
Hashing seems better than BST for all the operations. But in hashing, elements are
unordered and in BST elements are stored in an ordered manner. Also, BST is easy to
implement but hash functions can sometimes be very complex to generate. In BST, we
can also efficiently find floor and ceil of values.
Example: Hashing can be used to remove duplicates from a set of elements. Can also
be used to find the frequency of all items. For example, in web browsers, we can
check visited URLs using hashing. In firewalls, we can use hashing to detect spam.
We need to hash IP addresses. Hashing can be used in any situation where want
search() insert() and delete() in O(1) time.
This article is contributed by Abhiraj Smit. Please write comments if you find
anything incorrect, or you want to share more information about the topic discussed
above.

You might also like