Hash Functions

Importance of Hash function Why Hash-function matter? Chaining implementation of hashtable We will discuss about hashtable with chain. Insertion in the hashtable is O(1), so does lookup. Invoke hash function and see where is our bucket. Now go to the bucket and traverse the list until we find our element. Suppose we have 100 elements which are inserted in the hash function, then we have Lucky hash function - 1 element per bucket [Read More]

First non repeating element in the array

Question: Write an algorithm to find the first non-repeated character in a string. For example, the first non-repeated character in the string ‘abcdab’ is ‘c’. Answer: Seems trivial enough right? If a character is repeated, we should be able to search the string to determine if that character appears again. So if we go about doing this for every character in the string, our worst case run time would O(n^2). Here is some code to show this logic. [Read More]

Anagram Checker–To check if 2 strings are anagrams

An anagram is a type of word, the result of rearra… Unknown - Jul 1, 2014An anagram is a type of word, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. For example: orchestra can be rearranged into carthorse or cat can be rearranged into act. We can find out the anagram strings using below algorithm: [Read More]

Anagram Checker–To check if 2 strings are anagrams

Problem  Wap to find out if 2 strings are anagrams or not. Anagrams Two words are anagrams if one of them has exactly same characters as that of the another word. Example : Anagram & Nagaram are anagrams (case-insensitive).Similarily, abcd and abdc are anagrams, but abcd and abdce is not. Solution A simple way to check if two strings are anagrams is to find out if the numeric sum of the characters in the strings is equal. [Read More]