Hashing
Hashing
Applications
CT-157
Course Instructor
Engr. Vanesh Kumar
SEARCHING
Introduction
Process of finding an element within the list of
elements in order or randomly.
Retrieval: Successful Search.
A table of records in which a key is used for
retrieval is often called a SEARCH TABLE or
DICTIONARY.
Internal Searching – Whole data in main
memory
External Searching – Most data is kept in
auxiliary memory.
Searching Methods
Sequential or Linear Searching.
Binary Search.
Hashing.
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.
Efficiency:
Best – 𝑂(1)
𝑛
Average – 𝑂( )
2
Worst – 𝑂(𝑛)
Less efficient if array size is large.
Not efficient on sorted arrays.
Binary Search
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: 𝑂(𝑙𝑜𝑔2 𝑛).
Logic behind the technique:
First Half Second Half
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
_ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _
65(?)
Open Addressing
– Linear Probing
Handling Collisions
Chaining
Separate Chaining
Let each array element be the head of a chain.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
47 65 36 129 25 2501
35
Linear Probing
Linear Probing
Let key k be stored in element h(k)=t of the array
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
47 35 36 129 25 2501
65(?)