hashing is encryption process mostly used in programming language for security purpose.
This presentation will you understand all about hashing and also different techniques used in it for encryption process
6. SEQUENTIAL SEARCH
• Searches on unordered and ordered tables in sequential manner until the desired record is
not found or table end is not reached.
• It is simple and good for small arrays.
• Mostly used when data is not sorted.
• Less efficient if array size is large.
• Consumes a lot of time as compared to other techniques.
• Not efficient on sorted arrays.
7. BINARY SORT
• This technique works better on sorted arrays and can be applied only on sorted
arrays.
• Not applied on Linked Lists.
• Requires less number of comparisons than linear search.
• Efficiency: O(log2n).
• Logic behind the technique:
Second HalfFirst Half
mid=(low+high)/2
Last ValueFirst Value
8. EFFICIENCY:
• Best – O(1)
Constant time
• Average – O(n/2)
Here, n represents the number of elements in array
• Worst – O(n)
Here, n represents the number of elements in array
Apply NowApply NowApply Now
11. INTRODUCTION
Hashing is the transformation of long strings or information into a usually
shorter fixed-length value or key that represents the original string or
information.
Hashing is used to index and retrieve items in a database because it is
faster to find the item using the shorter hashed key than to find it using the
original value.
It is also used in many encryption algorithms.
A table of records in which a key is used for retrieval is often called a
SEARCH TABLE or DICTIONARY.
12. DICTIONARY
• A dictionary is a collection of elements
• Each element has a field called key
– (key, value)
• Every key is usually distinct.
• Typical dictionary operations are:
– Insert a pair into the dictionary
– Search the pair with a specified key
– Delete the pair with a specified key
13. HASH TABLE
• A hash table is a data structure that stores elements and allows insertions,
lookups, and deletions to be performed in O(1) time.
• A hash table is an alternative method for representing a dictionary
• In a hash table, a hash function is used to map keys into positions in a table.
This act is called hashing
• Hash Table Operations
– Search: compute f(k) and see if a pair exists
– Insert: compute f(k) and place it in that position
– Delete: compute f(k) and delete the pair in that position
• In ideal situation, hash table search, insert or delete takes (1)
14. WORKING OF HASH TABLE
• The table part is just an ordinary array, it is the Hash that we are interested in.
• The Hash is a function that transforms a key into address or index of array(table)
where the record will be stored. If the size of the table is N, then the integer will be in
the range 0 to N-1. The integer is used as an index into the array. Thus, in
essence, the key itself indexes the array.
• If h is a hash function and k is key then h(k) is called the hash of the key and is the
index at which a record with the key k should be placed.
• The hash function generates this address by performing some simple arithmetic or
logical operations on the key
15. HASH FUNCTIONS
• It Is the technique of using key to determine the address of a record so that no space
is wasted.
• Division method or function
• Mid-square method or function
• Folding method or function
16. DIVISION METHOD
• Division method computes the value of Hash as the remainder when the key is divided
by a specified prime number or it can be the size of the table.
• The hash function is defined as
H(k)=K( mod m)
Where K is the key and m is a prime number or size of the table.
17.
18. MIDSQUARE METHOD
• In this method we squared the KEY and then the HASH FUNCTION is defined as:
H(K)=I
Where I is the value which
we obtain by deleting equal digits
from both sides ok K(square).
20. FOLDING METHOD
• In this method we divide the key value in two parts. And then we add them.
FOR EXAMPLE:
K= 4012 1027
40+12=52 10+27=37
J=52 J=37
Here J is the value which we obtain by adding the KEY value.
21. ALGORITHM
• Our goal in choosing any hashing algorithm is to spread out the record as uniformly as
possible over the range of addresses available
• It has three steps
• Represent the key in any numerical form
• Fold and add
• Divide by the size of the address space and use the reminder as an address.
22. EXAMPLE
• Pairs are: (22,a),(33,c),(3,d),(72,e),(85,f)--(key, value) pairs
• Hash table is ht[0:7], m = 8 (where m is the number of positions in the hash table)
• Hash function h is k % m = k % 8
• Where are the pairs stored?
[0] [1] [2] [3] [4] [5] [6] [7]
[0] [1] [2] [3] [4] [5] [6] [7]
(72,e) (33,c) (85,f) (22,a)(3,d)
23. CHARACTERISTICS OF GOOD HASH
FUNCTION
The hash value is fully determined by the data being hashed.
The hash function uses all the input data.
The hash function "uniformly" distributes the data across the entire set of possible
hash values.
The hash function generates very different hash values for similar strings.
24. COLLISIONS AND THEIR RESOLUTION
• A collision occurs when two different keys hash to the same value
– E.g. For Table Size = 17, the keys 18 and 35 hash to the same value
– 18 mod 17 = 1 and 35 mod 17 = 1
• Cannot store both data records in the same slot in array!
25. COLLISION RESOLUTION
A method that is used to resolve the collision in Hash function is called Collision Resolution.
• Two different methods for collision resolution:
– Separate Chaining: Use a dictionary data structure (such as a linked list) to
store multiple items that hash to the same slot
– Closed Hashing (or probing): search for empty slots using a second function
and store item in first empty slot that is found
26. SEPARATE CHAINING
• Put a little dictionary at each entry
– choose type as appropriate
– common case is unordered linked list (chain)
• Properties
– performance degrades with length of chains
– can be greater than 1
3
2
1
0
6
5
4
a d
e b
c
h(a) = h(d)
h(e) = h(b)
27. CLOSED HASHING
Problem with separate chaining:
Memory consumed by pointers –
What if we only allow one Key at each entry?
– two objects that hash to the same spot can’t both go there
– first one there gets the spot
– next one must go in another spot
• Properties
– performance degrades with difficulty of finding right spot
a
c
e
3
2
1
0
6
5
4
h(a) = h(d)
h(e) = h(b)
d
b
28. APPLICATIONS
• File management- working out where to store records
• Comparing complex values
• Cryptography- creating digital signatures and passwords.
• Dictionaries
• Security systems
29. THANK YOUT A K E A S M I L E , T H E Y A R E F R E E