The simplest data searching algorithm is sequential search. In this method, we insert data into the tables in any order. In order to search for an entry in the table, we perform searching starting from the first element and perform the action sequentially until a matching entry is found or end of table is reached. In this case, the best-case performance is O(1), since matching entry is obtained in the first searching itself. However, the worst-case scenario occurs if the element to be searched is not in the table. When such a condition occurs, we need to search the whole table to conclude the element is not in the table. If there are ‘n’ number of elements in the table, the worst-case performance for sequential search will be O(n). As n becomes …show more content…
Let U = {0, 1,..,m-1} be the universe of ‘m’ keys from which an application draws its keys. If this universe of keys is reasonably small and if no two elements have the same key, then we can use an array to store the keys. Each slot in the array corresponds to a key in the universe U. Hence there will be ‘m’ slots in the array or Direct-address table, corresponding to each element in the universe. We can use the key value as index of the array to directly access the array location to see whether an element is present or not. This method works good for small universe of keys since the dynamic subset of keys that the application draws from the universe might not contain all the keys. This lefts a lot of unused slots if the universe is large and subset of keys drawn are small. Also if the universe is large, it would be difficult to have a large table of size |U|, since we might encounter space issues constrained by the memory size of the machine. However, this method is having the advantage that the worst-case computational complexity to check if an entry is present in the table is only …show more content…
This helps us to reduce the storage requirements considerably if the universal set is large and subset of keys is small. The storage requirements is bounded by Θ(|K|), whereas average-case searching time is O(1). In this scenario, instead of having |U| slots where element with key k, is stored at slot k, we are hashing the number of slots to |K| where |K| < |U| and store all the elements into these |K| slots using a mapping function called hash function. Hash function, h, is used to compute the slot for key, k, and element is stored in slot h(k). In other words, hash function h maps the universe U of keys in to hash table T[0,1,…,m-1]. Hashing reduces the range of array indices that need to be handled to m