To understand hashing, let's consider a small example where you want to store details of students in a Map, where key is the student ID and value is the student object. As student IDs can be alphanumeric, the number of possible keys is infinite. Now, in order to fetch a student's details from their ID, we first need to search the IDs and then fetch the details. It takes O(n) to do the required task.
To make it faster, we can slightly change the approach by storing the entries. Instead of storing each entry individually, we can store them based on the first character of the ID. If a student has an ID that starts with a, then we store their details in the 0th index, b in the first index, c in the second index, and so on. By following this approach, we can make our Map operate 26 times faster than the earlier approach.
If we look closely, we should be...