Recall & Review
beginner
What is a palindrome?
A palindrome is a word, number, phrase, or sequence that reads the same backward as forward, like 'madam' or '121'.
Click to reveal answer
beginner
How can you check if a string is a palindrome using two pointers?
Use two pointers: one at the start and one at the end of the string. Move them towards the center, comparing characters. If all pairs match, it's a palindrome.
Click to reveal answer
intermediate
Why is ignoring case important in palindrome detection?
Ignoring case ensures that uppercase and lowercase letters are treated the same, so 'Madam' is recognized as a palindrome just like 'madam'.
Click to reveal answer
intermediate
What is the time complexity of checking a palindrome in a string of length n?
The time complexity is O(n) because each character is checked at most once when comparing pairs from start and end.
Click to reveal answer
beginner
Show a simple C code snippet to check if a string is a palindrome.
#include
#include
#include
int isPalindrome(char str[]) {
int left = 0;
int right = strlen(str) - 1;
while (left < right) {
if (tolower(str[left]) != tolower(str[right])) {
return 0; // Not palindrome
}
left++;
right--;
}
return 1; // Palindrome
}
int main() {
char s[] = "Madam";
if (isPalindrome(s)) {
printf("Palindrome\n");
} else {
printf("Not Palindrome\n");
}
return 0;
}
Click to reveal answer
What does a palindrome string read the same as?
✗ Incorrect
A palindrome reads the same backward and forward.
Which method is commonly used to check palindrome in a string?
✗ Incorrect
Two pointers from start and end compare characters to check palindrome.
What should you do to ignore case when checking palindrome?
✗ Incorrect
Converting characters to the same case ensures case-insensitive comparison.
What is the time complexity of palindrome detection in a string of length n?
✗ Incorrect
Checking pairs from start and end requires O(n) time.
If the characters at the two pointers do not match, what can you conclude?
✗ Incorrect
A mismatch means the string cannot be a palindrome.
Explain how to check if a string is a palindrome using the two-pointer technique.
Think about comparing characters from both ends moving inward.
You got /5 concepts.
Describe why ignoring case is important in palindrome detection and how to implement it in C.
Consider how 'Madam' and 'madam' should be treated the same.
You got /4 concepts.
