The hollow butterfly star pattern keeps only the outline of the butterfly: two straight outer edges and two diagonals that meet in the middle, where the wings join.
Quick answer: Give every row 2n positions. Print a star on the outer columns 1 and 2n, and on the two diagonals j == i and j == 2n − i + 1. Run rows 1 to n, then the same rows from n back to 1.
This program is part of the Star Patterns collection.
Table of contents8 sections
Hollow Butterfly Star Pattern output
Output (n = 4):
* * ** ** * * * * * ** * * ** * * * * * ** ** * *

How the hollow butterfly star pattern works
Each wing of the solid butterfly is a right triangle; its outline is the outer column plus the slanted edge. The left wing’s slanted edge is where j == i, the right wing’s is its mirror, j == 2n − i + 1. On row n the two edges touch in the middle. The lower wings are the same rows printed in reverse, and here the middle row is printed twice so the body is two stars tall.
- Run the outer loop for
ifrom1ton, one row per pass (upper wings). - Go through
2 × npositions in the row. Print stars wherej = 1 or j = 2 × n or j = i or j = 2 × n − i + 1; print spaces everywhere else. - Move to the next line.
- Run the outer loop for
ifromndown to1, one row per pass (lower wings). - Go through
2 × npositions in the row. Print stars wherej = 1 or j = 2 × n or j = i or j = 2 × n − i + 1; print spaces everywhere else. - Move to the next line.
Key takeaways
- The outline is two outer columns plus two diagonals.
- The right diagonal mirrors the left one:
j == 2n − i + 1. - The two diagonals touch on the middle rows, forming the body.
- The lower half repeats row
n, matching the solid butterfly on this site.
Hollow Butterfly Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 4;
// upper wings
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
// lower wings
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Butterfly Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 4;
// upper wings
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
cout << "*";
else
cout << " ";
}
cout << endl;
}
// lower wings
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Butterfly Star Pattern in Java
public class HollowButterflyStar {
public static void main(String[] args) {
int n = 4;
// upper wings
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
// lower wings
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= 2 * n; j++) {
if (j == 1 || j == 2 * n || j == i || j == 2 * n - i + 1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Butterfly Star Pattern in Python
n = 4
# upper wings
for i in range(1, n + 1):
for j in range(1, 2 * n + 1):
if j == 1 or j == 2 * n or j == i or j == 2 * n - i + 1:
print("*", end="")
else:
print(" ", end="")
print()
# lower wings
for i in range(n, 0, -1):
for j in range(1, 2 * n + 1):
if j == 1 or j == 2 * n or j == i or j == 2 * n - i + 1:
print("*", end="")
else:
print(" ", end="")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(n²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
Why is the middle row printed twice?
Both halves include row n, so the body is two rows tall, the same as in the solid butterfly star pattern. Start the second half at n − 1 to print it once.
How do I make the butterfly wider?
Raise n. The width is always 2n and the height 2n, so the shape grows evenly.
Can I fill the wings with a different character?
Yes. Add an else if for cells between the outer column and the diagonal and print a dot or a hash there.









