google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Saturday, May 7, 2016

Hash Table

If we have a table organization and a search technique which retrieve the key in a single access ,it would be very efficient. To do so, the position of the key in the table should not depend upon the other keys but the location should be calculated on the basis of the key itself .Such an organization and search technique is called hashing .

In hashing the address or location of an identifier X is obtained by using some function f(X) which gives address of X in a table.

HASHING TERMINOLOGY
Hash function :- A function that transforms a key X into a table index is called a hash function.

Hash address:- The address of X computed by the hash function is called the hash address or home address of X.

Hash Table :- The memory available to maintain the symbol table is sequential . This is referred to as hash table .

Bucket :- Each hash table is partitioned into b buckets ht[0]......ht[b-1].
Each bucket is capable of holding 's' records . Thus , a bucket consists of 's' slots. When s=1 , each bucket can hold 1 record.
The function f(X) maps and identifier X into one of the 'b' buckets i.e. from 0 to b-1.

Synonyms :- Usually , the total number of possible values for identifier X is much larger  than the hash table size. Therefore the hash function f(X) must map several identifiers into the same bucket .
Two identifiers I1 and I2 are synonyms  if   f(I1) = f(I2)

Collision :- When two non identical identifiers are mapped into the same bucket , a collision is said to occur , i.e. f(I1)= f(I2). Hence all synonyms occupy the same bucket.

Overflow :- An overflow is said to occur when an identifier gets mapped onto a full bucket.
When s=1 ,i.e. ,a bucket contains only one record ,collision and overflow occur simultaneously . Such a situation is called a Hash clash.

Load factor :- If n is the total number of identifiers in the table and t is the table size , the load factor is : lf = n/t
It represents the fraction of the table that is occupied .

HASHING FUNCTION
A hashing function f transforms an identifier X  into a bucket address in the hash table .The desirable properties of such a function are as follows.
i.  It should be easily computable .
ii. It should minimize the number of collisions .
iii. The hash function should compute the address,which depends on all or most of the characters in the identifier .
iv.  It should yield uniform bucket addresses for random inputs . Such a function is called a uniform hash function.
Several uniform hash functions are in use some of them are
1 Mid Square
2 Division
3 Folding
4 Digit Analysis

Templates in C++

C++ supports a mechanism known as template to implement the concept of generic programming .

Templates allows us to generate a family of classes or a family of functions to handle different types.

Template classes and functions eliminate code duplication for different types and thus make the program development easier and more manageable.

We can use multiple parameters in both the class templates and function templates.

A specific class created from a class template is called a template class and the process of creating a template class is known as instantiation. Similarly, a specific function created from a function template is called a template function.

Like other functions, template functions can be overloaded.

Member functions of a class template must be defined as function templates using the parameters of the class template.

We may also use non - type parameters such basic or derived data types as arguments templates.


अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...