Skip to content

Instantly share code, notes, and snippets.

@Hydra9268
Last active November 18, 2024 06:05
Show Gist options
  • Save Hydra9268/501ff8057bb7685d4bfa927806a40b5b to your computer and use it in GitHub Desktop.
Save Hydra9268/501ff8057bb7685d4bfa927806a40b5b to your computer and use it in GitHub Desktop.
Using Two-Letter Keys (e.g., AA, AB, AC) Three-Letter Keys (e.g., AAA, AAB, AAC)
A hash table for two-letter keys could use a hash function like:

hash(key) = 26 × index_of(first_letter) + index_of(second_letter)

For AA, AB, AC:
- AA → 26 × 0 + 0 = 0
- AB → 26 × 0 + 1 = 1
- AC → 26 × 0 + 2 = 2

This maps each two-letter key to a unique slot in a table with size 26 × 26 = 676 spaces.
A hash table for three-letter keys might extend this idea:

hash(key) = 26² × index_of(first_letter) + 26 × index_of(second_letter) + index_of(third_letter)

For AAA, AAB, AAC:
- AAA → 26² × 0 + 26 × 0 + 0 = 0
- AAB → 26² × 0 + 26 × 0 + 1 = 1
- AAC → 26² × 0 + 26 × 0 + 2 = 2

This maps each three-letter key to a unique slot in a table with size 26 × 26 × 26 = 17,576 spaces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment