DS – Hash Search Algorithm

Hash Search:

  • One of the searching algorithms to search for an element in the list.
  • We store the elements using their index.
  • Finding the index of element is the concept of linear probing.
  • In linked list, all elements connected in linear fashion.
  • To access nth element, n traversal required -> O(n)

Solution:

  • Using hash table, we can store elements.
  • We can take any size of hashtable, based on the table, indexes of elements will decide.
  • Elements: 32, 78, 9, 21, 44, 67, 13, 92, 76, 81

Linear list:

Hash Table list:

Constructing the Hash table:

            struct Node
            {
                        int data;
                        struct Node *link;
            };

Operations:

  1. Insert
  2. Search

Table creation:

Insertion in to Hash table:

Searching logic:

Scroll to Top