Hash table with quadratic method

2

I am implementing a hash table with quadratic exploration method. My question is regarding the 0 position of the vector used for table implementation. Here is the code below:

public boolean inserir(Pessoa item) {
    int valorHash = hash(item.getCelular());
    int contador = 1;
    int inicialHash = valorHash;

    while(bancoDados[valorHash] != null && !(bancoDados[valorHash].getCelular().equals(-1))) {
        valorHash += (contador*contador);
        contador++;
        valorHash %= tamanhoMax;
    }

    bancoDados[valorHash] = item;

    return true;

}

Through this method position 0 will never be found for an insert. Should I ignore this position in the vector and work with the remainder or is there any way to make my hash value ( valorHash ) arrive at position 0?

NOTE: I use a person's cell number to generate valorHash in another method. When a person is removed from my table I replace them with someone else, but with an invalid cell number (-1), to indicate that position is available.

    
asked by anonymous 08.02.2016 / 20:28

1 answer

0

Position 0 of your table will be found for seamless insertion, whenever the hash value of an object is a multiple of the table size, for example, let's assume you have a 17-position table, and the hash has been 12 but there has been a collision, so the next hash will be h = (12 + 1 * 1)% 17 = 13, if there is also a collision at position 13, the next hash will be h = (13 + 2 * 2)% 17 = 0, note that the remainder of the division by 17 by 17 is 0, the same would happen if at any time the hash were 34 or 51, which are multiples of 17.     

28.09.2016 / 16:06