The alphabet bridge pattern, also called the reverse character bridge, starts with the palindrome ABCDEDCBA and opens a gap in the middle that grows by two spaces each row, until only the two A pillars are left.
Quick answer: Each row is 2n β 1 characters wide. For each column work out k, the letter number counted from the nearer end of the row: j on the left half and 2n β j on the right. Print the letter when k β€ n β i + 1 and a space otherwise.
This program is part of the String Patterns collection.
Table of contents8 sections
Alphabet Bridge Pattern output
Output (n = 5):
ABCDEDCBA ABCD DCBA ABC CBA AB BA A A

How the alphabet bridge pattern works
Looking at the row from both ends at once makes the code short. Column 1 and column 2n β 1 are both A, columns 2 and 2n β 2 are both B, and so on, so k is the letter for both halves. Each row hides the letters above a limit, n β i + 1, which starts at E and falls by one per row. Hiding the highest letter from both halves at once is what opens the gap two spaces at a time.
- Run the outer loop for
ifrom 1 ton. - For each column
jfrom 1 to2n β 1, setk = jifj β€ n, otherwisek = 2n β j. - Print letter
k('A' + k β 1) ifk β€ n β i + 1, otherwise a space. - Move to the next line.
Key takeaways
- Columns the same distance from either end hold the same letter.
- Each row hides every letter above
n β i + 1. - The gap opens by two spaces per row: one letter disappears from each half.
- The first row is the only one where E appears, and it appears once.
Alphabet Bridge Pattern in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n - 1; j++) {
int k = (j <= n) ? j : 2 * n - j; /* letter number, counted from the nearer end */
printf("%c", k <= n - i + 1 ? 'A' + k - 1 : ' ');
}
printf("\n");
}
return 0;
}Alphabet Bridge Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n - 1; j++) {
int k = (j <= n) ? j : 2 * n - j; // letter number, counted from the nearer end
cout << (k <= n - i + 1 ? char('A' + k - 1) : ' ');
}
cout << endl;
}
return 0;
}Alphabet Bridge Pattern in Java
public class AlphabetBridge {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n - 1; j++) {
int k = (j <= n) ? j : 2 * n - j; // letter number, counted from the nearer end
System.out.print(k <= n - i + 1 ? (char) ('A' + k - 1) : ' ');
}
System.out.println();
}
}
}Alphabet Bridge Pattern in Python
n = 5
for i in range(1, n + 1):
for j in range(1, 2 * n):
k = j if j <= n else 2 * n - j # letter number, counted from the nearer end
print(chr(64 + k) if k <= n - i + 1 else " ", end="")
print()Time and space complexity
The program prints n(2n β 1) characters, so it runs in O(nΒ²) time with O(1) extra memory.
Frequently asked questions
How do I make the gap start on the first row?
Use k β€ n β i as the test and print n letters on each side. The first row then reads ABCDE EDCBA, with the E doubled around a one-space gap.
Is this the same as the number bridge?
It is the same shape upside down and with letters. The number bridge starts with a wide gap and closes it; this bridge starts closed and opens.
Can I print it with numbers?
Yes. Print k instead of the letter: 123454321, then 1234 4321, and so on.






