The correct option is Hashing
CONCEPT:
In linear search, every element of a given list is compared one by one with the given key without skipping any element.
It is useful when we need to search for an item in a small unsorted list, but the time is taken to search the list increases as the size of the list increases.
In binary search, the key to be searched is compared with the middle element of a sorted list,
i) If the element at the middle position matches the key the search is successful
ii) If the element at the middle position is greater than the key then the key element may be present in the left part of the list
iii) If the element at the middle position is smaller than the key, then the key element may be present in the right part of the list
This process continues till the element is found or the list is traversed completely.
Hash-based searching requires only one key comparison to find the position of a key, provided every element is present at its designated position decided by a hash function.
It uses a list as a storage medium and uses the hash technique/formula to generate the index which an element is to be inserted or is to be located from.
If two elements map to the same slot in the hash table, it is called collision, and the process of identifying a slot for the second and further items in the hash table in the event of a collision is called collision resolution.
For example, consider a list of length 5 and the hash function: h(element)= element%5
to store the collection of numbers 4, 12, 5, 3, and 9 in a hash table.
Key | Hash | List index |
4 | 4%5=1 | 1 |
12 | 12%5=2 | 2 |
5 | 5%5=0 | 0 |
3 | 3%5=3 | 3 |
9 | 9%5=4 | 4 |
The resulting list will have elements in the following order = [ 5, 4, 12, 3, 9 ]
If we want to search for key = 12, requires only one key comparison to find the position of key 12 as h(12) = 12 % 5 = 2
The key element 12 is present at index 2 of the list.