Direct Address Table is a data structure that has the capability of mapping records to their corresponding keys using arrays. In direct address tables, records are placed using their key values directly as indexes. They facilitate fast searching, insertion and deletion operations.
We can understand the concept using the following example. We create an array of size equal to maximum value plus one (assuming 0 based index) and then use values as indexes. For example, in the following diagram key 21 is used directly as index.
- Searching in O(1) Time: Direct address tables use arrays which are random access data structure, so, the key values (which are also the index of the array) can be easily used to search the records in O(1) time.
- Insertion in O(1) Time: We can easily insert an element in an array in O(1) time. The same thing follows in a direct address table also.
- Deletion in O(1) Time: Deletion of an element takes O(1) time in an array. Similarly, to delete an element in a direct address table we need O(1) time.
- Prior knowledge of maximum key value
- Practically useful only if the maximum value is very less.
- It causes wastage of memory space if there is a significant difference between total records and maximum value.
Hashing can overcome these limitations of direct address tables.
How to handle collisions?
Collisions can be handled like Hashing. We can either use Chaining or open addressing to handle collisions. The only difference from hashing here is, we do not use a hash function to find the index. We rather directly use values as indexes.
- Address Calculation Sort using Hashing
- Hash Table vs STL Map
- Sparse Table
- Advantages of BST over Hash Table
- Range sum query using Sparse Table
- Implementing our Own Hash Table with Separate Chaining in Java
- Implementing own Hash Table with Open Addressing Linear Probing in C++
- Minimum value to add to arr[i] so that an array can be split at index i with equal sum
- Number of subarrays having sum of the form k^m, m >= 0
- Compute maximum of the function efficiently over all sub-arrays
- Check if product of array containing prime numbers is a perfect square
- Maximum number of continuous Automorphic numbers
- Maximum consecutive one’s (or zeros) in a binary circular array
- Maximum volume of cube for every person when edge of N cubes are given
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Srilekha_Paul