The Division Method
There are many hash functions out there that are considered effective. In this chapter, we’ll focus on one particular hash function design. It’s simpler than most of the alternative approaches, but still effective.
The hash function I’ll demonstrate doesn’t have a fancy name, but is often called Division Hashing or the Division Method. There are several variants and optimizations of this method, but I’ll present it in its most basic form.
Before we start, let’s define a couple of variables. We’ll use the variable K to refer to the integer we’re hashing, and M will refer to the size of the array. Although I personally would have chosen other alphabet letters, these are the variables that are often used in the literature.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access