Warning: Undefined array key "amp-addthis" in /home/tgagmvup/onlinestudy.guru/wp-content/plugins/addthis/backend/AddThisSharingButtonsFeature.php on line 101
lang="en-US"> What is hashing in java - onlinestudy.guru
Site icon onlinestudy.guru

What is hashing in java

Hashing is a method of sorting and indexing data. The idea behind hashing is to allow large amount of data to be indexed using keys commonly created by formulas.

Why do we need hashing
It is time efficient in case of search operation.

Data Structure Time Complexity of Search
ArrayO(logN)
LinkedListO(N)
TreeO(logN)
HashingO(1)/O(N)

Hashing terminology

Hash Functions

    /**
     * @param number number which you want to insert
     * @param cellNumber total number of cells you want
     * @return  it will return reminder
     */
    //it is mod function
    public static int mod(int number, int cellNumber) {
        return (number % cellNumber);
    }

    /**
     * @param word which word you want to insert
     * @param cellNumber total cells you want
     * @return it will return reminder 
     */
    // it is modASCII
    public static int modASCII(String word, int cellNumber) {
        int total = 0;
        for (int i = 0; i < word.length(); i++) {
            total += word.charAt(i);
            System.out.println("char at " + word.charAt(i));
            System.out.println(total + " total");
        }
        return total % cellNumber;
    }

Properties of hash function
It distributes hash value across hash tables.

What will happen if hash table is full.

Practical use of hashing

Store hashvalue insted of actual password.
File system:- file path is mapped to physical location on disk.

Git hub

Exit mobile version