Hashing-Based Symbol Table Addressing: Computing the Initial Position for Key 27
A symbol table using hashing stores each key in a table slot determined by a hash function . For division hashing, a common hash function is , where is the table size, and the output is an index in the range . This modulo/remainder approach is standard for mapping keys to table addresses. 2
Key idea: the “initial position” is simply for .
We are given the options:
- (i)
- (ii)
- (iii)
- (iv)
Footnotes
-
Hash function - Wikipedia - Describes using modulo in hashing for mapping keys into table indices. ↩
-
8.1. Hashing — CS3 Coursenotes (ODSA) - States hashing maps keys to positions and typical indexing for slots. ↩ ↩2
Compute the initial hash table position for key 27
- 1Step 1
Given and , compute .
- 2Step 2
Since and , the remainder is .
- 3Step 3
Therefore, , which corresponds to option (ii).
So the correct initial position is (ii) .
This follows directly from the definition of modulo as the remainder after division: where and .
Footnotes
-
Modulo Calculator — definition of remainder - Explains via and the remainder interpretation. ↩
Pro Tip
For , you can compute quickly by finding the remainder of after removing the largest multiple of not exceeding —no need for long division.
Footnotes
-
Hash function - Wikipedia - Describes using modulo in hashing for mapping keys into table indices. ↩
Indexing convention
Most hashing descriptions index slots from to when using modulo, so the modulo remainder is used directly as the address in that range. If a course uses -based indexing, the answer would shift by , but the modulo definition itself still yields remainder .
Footnotes
-
8.1. Hashing — CS3 Coursenotes (ODSA) - States hashing maps keys to positions and typical indexing for slots. ↩
From key to address in a hashed symbol table
Hashing
1Apply to map the key to a slot."
Initial position
2Use the remainder as the first candidate table index."
Collision handling (if needed)
3If the slot is taken, a collision resolution strategy determines the next probe address."
Footnotes
-
Symbol Table and Hashing (lecture handout PDF) - Defines collisions and collision resolution policies. ↩
Multiple-choice options vs computed remainder
Computed
Quick conceptual check
Knowledge Check
For a symbol table of size using , what is the initial position for key ?
Explore Related Topics
Symbol Tables in Compilers: Structure, Scope, and Semantic Analysis
Lexical Analysis Token Counting: `while(count<=10) count = count + 1;`
The course explains how a lexical analyzer tokenizes the C statement while(count<=10) count = count + 1; and why the standard exam answer is 11 tokens.
- Keywords, identifiers, literals, operators, and delimiters each count as one token; whitespace is ignored.
<=is recognized as a single relational‑operator token due to the longest‑match rule.- The full lexical split shows 12 visible symbols, but typical MCQ conventions omit one delimiter, giving 11 tokens.
- Understanding token categories helps avoid common exam traps such as counting delimiters incorrectly.
Adding Hexadecimal Numbers: $2ABC + 98F2$