What is a Palindrome?
Famous examples, why normalization matters, how the longest palindromic substring is found, and palindromes in numbers and dates.
Definition
A palindrome is a word, phrase, number, or sequence that reads the same forwards and backwards. The name comes from the Greek palindromos — "running back again."
The simplest examples are single words:
racecar → racecar ✓ level → level ✓ civic → civic ✓ radar → radar ✓ noon → noon ✓ madam → madam ✓
Each reads identically whether you start from the left or the right.
Why normalization matters
Most interesting palindromes are phrases, not single words. Phrases include spaces, punctuation, and mixed case — none of which affect the palindrome property semantically. To check them correctly, you normalize first:
Ignore case
"Never odd or even" → "neveroddoreven" → palindrome ✓
Ignore spaces
"A man a plan a canal Panama" → "amanaplanacanalpanama" → palindrome ✓
Ignore punctuation
"Was it a car or a cat I saw?" → "wasitacaroracatisaw" → palindrome ✓
All three normalization options are independent. A strict checker (no normalization) only matches exact-character palindromes like "racecar." A lenient checker (all three) catches phrases like "A man, a plan, a canal: Panama."
Famous palindromes
| Palindrome | Notes |
|---|---|
| "A man, a plan, a canal: Panama" | Classic English phrase palindrome — attributed to Leigh Mercer (1948) |
| "Never odd or even" | Short phrase, works with case + space normalization |
| "Was it a car or a cat I saw?" | Works with case + punctuation normalization |
| "Do geese see God?" | Requires case normalization |
| "Murder for a jar of red rum" | Multiword with space + case normalization |
| "In girum imus nocte et consumimur igni" | Latin palindrome — "We wander at night and are consumed by fire" |
| Aibohphobia | The fear of palindromes — itself a palindrome (a joke term) |
Numeric palindromes and palindrome dates
Numbers can be palindromes too — any integer that reads the same forwards and backwards:
11, 121, 1221, 12321, 1234321, ...
Calendar dates in certain formats also form palindromes. The frequency depends on the date format:
| Date | Format | Digits |
|---|---|---|
| 02/02/2020 | MM/DD/YYYY | 02022020 ✓ |
| 12/02/2021 | MM/DD/YYYY | 12022021 ✓ |
| 2011-11-02 | YYYY-MM-DD | 20111102 ✓ |
| 2021-12-02 | YYYY-MM-DD | 20211202 ✓ |
The longest palindromic substring
For any block of text, the longest palindromic substring is the longest contiguous sequence within it that is itself a palindrome. This is a well-known computer science problem with an efficient solution.
The naive approach checks every possible substring — O(n³) time. The standard efficient approach, Manacher's algorithm, finds it in O(n) time by expanding outward from each character (treating each position as a potential center):
For "abacaba": Expand from 'a' (index 0): just "a" Expand from 'b' (index 1): "aba" Expand from 'a' (index 2): "bacab" → "abacaba" ← longest Expand from 'c' (index 3): "acaba" → stops ... Result: "abacaba" (the entire string)
The algorithm handles both odd-length palindromes (centered on a single character) and even-length palindromes (centered between two characters) simultaneously.
Frequently asked questions
- Is a single character a palindrome?
- Yes, by definition — any single character reads the same forwards and backwards. An empty string is also technically a palindrome (vacuously true), though most checkers require at least two characters for the result to be meaningful.
- Why does "A man, a plan, a canal: Panama" pass?
- With spaces, punctuation, and case ignored, the normalized string is "amanaplanacanalpanama" — which reads identically forwards and backwards. The normalization options are what make phrase palindromes work.
- What is the difference between a palindrome and an anagram?
- A palindrome reads the same forwards and backwards. An anagram is a word or phrase formed by rearranging the letters of another. They are unrelated: "racecar" is a palindrome but not an anagram of anything common; "listen" is an anagram of "silent" but not a palindrome.
- Are there very long word palindromes in English?
- "Aibohphobia" (11 letters, the fear of palindromes) is one of the longest single English palindrome words, though it was coined humorously. Other long natural palindromes include "detartrated" (12 letters, a chemistry term) and "rotator" (7 letters).