A language has 28 different letters in total. Each word in the language is…
2024
A language has 28 different letters in total. Each word in the language is composed of maximum 7 letters. You want to create a data-type to store a word of this language. You decide to store the word as an array of letters. How many bits will you assign to the data-type to be able to store all kinds of words of the language?
- A.
35
- B.
39
- C.
34
- D.
32
Show answer & explanation
Correct answer: A
To digitally encode a set of L distinct symbols, every symbol needs at least ceil(log2 L) bits — the smallest power of two that is greater than or equal to L fixes the minimum bit-width, since n bits can represent exactly 2n distinct values.
The language has 28 letters. Since 24 = 16 is less than 28, but 25 = 32 is at least 28, each letter needs 5 bits to be uniquely encoded.
The word is stored as an array with one slot per letter, and the array must be sized for the worst case — the maximum word length of 7 letters.
Total bits required = bits per letter × maximum number of letters = 5 × 7 = 35 bits.
Check: 5 bits give 25 = 32 distinct codes, enough to cover all 28 letters, while 4 bits (24 = 16) would fall short — confirming 5 bits per letter is both necessary and sufficient. Scaling to the 7-letter array gives 5 × 7 = 35 bits.
