Our website loads in split second powered by Schema Theme. Thanks to MyThemeShop

Finding duplicates in an array using Hashtables -O(n)

We have seen the Brute force and sorted array solutions for the problem statement, Now to even minimize the time complexity of finding duplicates we’ll introduce hashing techniques so that, the problem statement can take only O(n) time. We’ll conditionally add input array elements to HashMap. We’ll check for the input array element that we are going to add into HashMap whether it is available in the map or not, if it is not available we’ll add element as key and value as zero. If it is available in the map then increment the value by 1 for the respective keys. Here is the technique for finding duplicates in an array using hashtables.

Finding duplicates in a array using Hashtables -O(n)

 Finding duplicates using List and Hashset in Java

Sample Test Client for the above programs