The hollow half diamond star pattern keeps only the outline of the half diamond: a straight left edge and a slanted right edge that points out to the right. Some sites call it the hollow right Pascal’s triangle.
Quick answer: Print a hollow right triangle for rows 1 to n, then the same rows again from n − 1 back down to 1. On row i a position gets a star only when j == 1 or j == i; the positions in between are spaces.
This program is part of the Star Patterns collection.
Table of contents8 sections
Hollow Half Diamond Star Pattern output
Output (n = 5):
* ** * * * * * * * * * * ** *

How the hollow half diamond star pattern works
The solid half diamond prints i stars per row, growing and then shrinking. The hollow version prints the same i positions but fills only the first and the last, which are the two edges. Row 1 and row 2 have no inside yet, so they look solid. Running the second half from n − 1 keeps the widest row from being printed twice.
- Run the outer loop for
ifrom1ton, one row per pass (upper half). - Go through
ipositions in the row. Print stars wherej = 1 or j = i; print spaces everywhere else. - Move to the next line.
- Run the outer loop for
ifromn − 1down to1, one row per pass (lower half). - Go through
ipositions in the row. Print stars wherej = 1 or j = i; print spaces everywhere else. - Move to the next line.
Key takeaways
- A hollow shape is the solid shape with an edge test in the inner loop.
- The two edges are the first position (
j == 1) and the last one (j == i). - The lower half starts at
n − 1so the middle row appears once. - The gap inside grows by one space per row, up to
n − 2spaces in the middle.
Hollow Half Diamond Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 5;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
printf("*");
else
printf(" ");
}
printf("\n");
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Half Diamond Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
cout << "*";
else
cout << " ";
}
cout << endl;
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Half Diamond Star Pattern in Java
public class HollowHalfDiamondStar {
public static void main(String[] args) {
int n = 5;
// upper half
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
// lower half
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Half Diamond Star Pattern in Python
n = 5
# upper half
for i in range(1, n + 1):
for j in range(1, i + 1):
if j == 1 or j == i:
print("*", end="")
else:
print(" ", end="")
print()
# lower half
for i in range(n - 1, 0, -1):
for j in range(1, i + 1):
if j == 1 or j == i:
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 do the first two rows look solid?
Row 1 has a single position and row 2 has two, so every position is an edge. The gap only appears once a row has three or more positions.
How do I point it to the left instead?
Right-align the rows: print stars where j == n − i + 1 or j == n on an n-wide row. That is the hollow mirrored half diamond.
How do I let the user choose the size?
Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.











