<DS/>DS_VISUALIZER
FoundationsOOPArraysLinked ListStacksQueuesTreesGraphsHashingStrings
exploreExplore
homechevron_rightTopicschevron_rightHashingchevron_rightHash Functions
functions

HASHING · HASH FUNCTIONS

Hash Functions

The arithmetic that turns a key into a table index — worked out digit by digit.

Choose a method

percentarrow_outward

Division Method

h(k) = k mod m — quotient, remainder, and why m should be prime.

O(1)O(1)◍ 0/6
closearrow_outward

Multiplication Method

h(k) = ⌊m·frac(k·A)⌋ with Knuth's golden-ratio A.

O(1)O(1)◍ 0/6
content_cutarrow_outward

Folding Method

Chop long keys into digit groups, sum, then mod m.

O(d)O(1)◍ 0/6
abcarrow_outward

String Hashing

Rolling hash: h = (h·31 + code) mod m, char by char.

O(L)O(1)◍ 0/6