0

I am studying programming and in the school book it states that given key x, hashtable A[] and hash function h() the key x it is stored in A[h(x)-1] position (with C++ implementation). However, using as hash function the function h(x)=xmodM, where M is the length of the hashtable, I don't get where keys with mod 0 are stored. For instance, if M=10 and x=60, where I should store the key value? Thanks in advance!

gdaras
  • 9,401
  • 2
  • 23
  • 39

1 Answers1

1

It depends on how h() is defined, if it accepts values starting with 1, then this is why you have -1 in this formula: h(x)-1. Arrays in c++ are indexed starting from 0.

If you compute reminder of dividing of 60 by 10 in c++, then you will get value 0 (60 % 10 = 0). In such case it makes no sense to subtract -1.

marcinj
  • 48,511
  • 9
  • 79
  • 100
  • Thanks for the answer, I couldn't agree more. The thing is that the book is getting a bit confusing when it comes to that specific example and that's why I asked – gdaras Sep 14 '16 at 11:56