Recall & Review
beginner
What is character frequency counting?
It is the process of counting how many times each character appears in a given string or text.
Click to reveal answer
beginner
Which data structure is commonly used to store character frequencies in C?
An array of integers indexed by character codes (like ASCII values) is commonly used to store frequencies.
Click to reveal answer
beginner
Why do we often use an array of size 256 for character frequency counting in C?
Because ASCII characters have 256 possible values, so an array of size 256 can store frequency for each possible character.
Click to reveal answer
beginner
How do you update the frequency count for a character in C?
You increase the value at the array index corresponding to the character's ASCII code by 1 each time the character is found.
Click to reveal answer
beginner
What is the time complexity of counting character frequencies in a string of length n?
The time complexity is O(n) because you scan the string once and update counts.
Click to reveal answer
What data structure is best to count character frequencies in a fixed ASCII set in C?
✗ Incorrect
An integer array of size 256 is best because it directly maps each ASCII character to a frequency count.
If you have the string "hello", what is the frequency of 'l'?
✗ Incorrect
The character 'l' appears twice in "hello".
What is the initial value of frequency counts before counting characters?
✗ Incorrect
Frequency counts start at zero because no characters have been counted yet.
Which loop is typically used to count characters in a string in C?
✗ Incorrect
A for loop is commonly used to iterate over each character in the string.
What happens if you try to count characters beyond the string's null terminator in C?
✗ Incorrect
Accessing characters beyond the null terminator leads to undefined behavior.
Explain how to count the frequency of each character in a string using C.
Think about using an array indexed by ASCII values and a loop.
You got /4 concepts.
Describe why an array of size 256 is used for character frequency counting in C.
Consider the range of ASCII codes.
You got /4 concepts.
