Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
B.Tech S3 (S) Examinations May 2026 (2024 Scheme)QP 06PCCST303112504Part A · Q83 marksCO4Module 4asked in 2 papers

Question 8

Explain any three hashing functions with examples.

Topics: Hashing and hash functions

Watch this exact question run

Loading visualizer…

Solution

A hash function maps a key to a table index in 0 … m − 1. Any three of the following are acceptable; examples below are computed by the hashing engine.

  • Division: h(k) = k mod m. Choose m prime and not close to a power of 2.
  • Mid-square: square the key and take the middle r digits (r = digits needed to address the table).
  • Folding (shift): split the key into parts of r digits, add the parts, then take the result mod m. Boundary folding reverses every other part before adding.
  • Digit analysis: for a known, static set of keys, examine every digit position and keep the positions whose digits are most evenly spread; the selected digits form the address.
Worked examples (generated)checked by code
  • division (m = 13): h(1276) = 1276 mod 13 = 2
  • midsquare (m = 100): 3205² = 10272025; middle 2 digits = 72 → 72
  • folding (m = 100): split 123456 into 2-digit parts: 12 + 34 + 56 = 102; 102 mod 100 = 2

How to write it in the exam

Write the definition + formula + one numeric example for each of three methods (division, mid-square, folding is the safest choice).

How this answer was verified
  • tests/hashing-search.test.ts (hash function unit tests)

Similar questions