Shape Rule
Outline only
Apex, widening waist, then narrowing tip — stars on edges only.

A hollow diamond stacks an inverted V (Program 7) on top of a V (Program 8 style), sharing the same if (i == j) / if (i == k) legs and skipping a duplicate middle row by starting the lower half at rows - 1. This tutorial covers both halves, a live preview, algorithm steps, worked Python examples, edge cases, and complexity.
Outline only
Apex, widening waist, then narrowing tip — stars on edges only.
i = 1..rows
Program 7’s inverted hollow V grows to the waist.
i = rows-1..1
Program 8’s V mirrors down without reprinting the waist.
j + k
Identical inner loops on both halves — star when indices match.
1–12 rows
Pick a height and draw the hollow diamond instantly.
2n - 1 lines
About 2n−1 rows × Θ(n) cells → O(n²) time, O(1) extra space.
A hollow diamond is two familiar outlines stacked: widen with an inverted V, then narrow with a V — stars only on the diagonals.
If you already know Program 7 and Program 8, this page is mostly composition: run the first half fully, then the second from rows - 1. For a solid fill, see Program 10.
Composition beats reinventing formulas. Once halves click, diamonds (hollow or filled) become “stack and skip the duplicate waist” — a reusable design habit.
Upper Program 7 + lower Program 8.
Lower starts at rows - 1.
Same j/k equality tests.
Every line is 2n - 1 characters.
In short: print Program 7 for i = 1..rows, then the same row body for i = rows-1..1 — one waist, full hollow diamond.
Given a positive integer rows, print a hollow diamond outline of * characters with 2 * rows - 1 lines, each of width 2 * rows - 1.
# rows = 5 (spaces shown as ·) — 9 lines, width 9
# ····*····
# ···*·*···
# ··*···*··
# ·*·····*·
# *·······*
# ·*·····*·
# ··*···*··
# ···*·*···
# ····*···· | Item | Type | Description |
|---|---|---|
rows | int | Half-height to the waist (typically ≥ 1). Total lines = 2 * rows - 1. |
| Printed output | text | Hollow diamond outline; interior spaces only. |
for i from 1 to rows: // upper half
print_row(i, rows)
for i from rows - 1 down to 1: // lower half
print_row(i, rows)
print_row(i, rows):
for j from rows down to 1:
print "*" if i == j else " "
for k from 2 to rows:
print "*" if i == k else " "
print newline | Approach | Idea | Best for |
|---|---|---|
| Two outer loops | Program 7 then Program 8 from rows-1 | Learning and interviews |
| Helper + ternaries | One print_row method reused twice | Cleaner demos after halves click |
| Goal | Pattern |
|---|---|
| Upper half | for i in range(1, rows + 1): |
| Lower half | for i in range(rows - 1, 0, -1): |
| Left / right legs | j = rows..1 + k = 2..rows with i == j / i == k |
| Line count & width | 2 * rows - 1 |
| Avoid double waist | Never start lower half at i == rows |
| Filled variant | See Program 10 |
Same legs — stacking and fill rules define the family.
upper onlyInverted hollow V
lower onlyUpright hollow V
7 + 8Hollow diamond outline
solid fillFilled diamond — spaces + odd stars
Reach for a hollow diamond when teaching composition after the V halves are solid.
Capstone for the hollow-outline mini-series.
“Reuse, don’t rewrite” — stack known blocks.
Outline first; then switch to solid star runs in Program 10.
Starting lower at rows vs rows - 1 is a classic bug.
Console teaching pattern — not how you build app screens.
Key benefit: proves complex shapes are often stacked simpler ones — with one careful off-by-one at the seam.
Choose a height between 1 and 12 and draw the hollow diamond in the browser.
Three complete Python programs — classic dual outer loops, console input, and a reusable row helper with ternaries. Click View Output to reveal sample console results.
Print a five-row-half hollow diamond with two outer loops.
rows = 5Upper i = 1..rows, lower i = rows-1..1, same j/k bodies.
rows = 5
# Upper half: i = 1 .. rows
for i in range(1, rows + 1):
for j in range(rows, 0, -1):
if i == j:
print("*", end="")
else:
print(" ", end="")
for k in range(2, rows + 1):
if i == k:
print("*", end="")
else:
print(" ", end="")
print()
# Lower half: avoid duplicate widest row
for i in range(rows - 1, 0, -1):
for j in range(rows, 0, -1):
if i == j:
print("*", end="")
else:
print(" ", end="")
for k in range(2, rows + 1):
if i == k:
print("*", end="")
else:
print(" ", end="")
print() The first loop prints 5 lines (apex to waist). The second prints 4 more (waist−1 to tip) — 9 lines total, waist printed once.
Let the user choose the half-height at runtime.
Read rows with input() and int() (wrap in try/except ValueError in real apps).
rows = int(input("Enter the number of rows: "))
for i in range(1, rows + 1):
for j in range(rows, 0, -1):
if i == j:
print("*", end="")
else:
print(" ", end="")
for k in range(2, rows + 1):
if i == k:
print("*", end="")
else:
print(" ", end="")
print()
for i in range(rows - 1, 0, -1):
for j in range(rows, 0, -1):
if i == j:
print("*", end="")
else:
print(" ", end="")
for k in range(2, rows + 1):
if i == k:
print("*", end="")
else:
print(" ", end="")
print() Same dual-half core as Example 1; only the source of rows changes. Non-numeric input raises ValueError with bare int(input()) — use try/except for safer labs.
Extract one row printer and call it from both halves.
Reuse print_row so the diamond is clearly “upper then lower.”
def print_row(i, rows):
for j in range(rows, 0, -1):
print("*" if i == j else " ", end="")
for k in range(2, rows + 1):
print("*" if i == k else " ", end="")
print()
rows = 5
for i in range(1, rows + 1):
print_row(i, rows)
for i in range(rows - 1, 0, -1):
print_row(i, rows) Same geometry as Example 1; duplication of the leg loops is gone. Great when you already understand Programs 7 and 8 and want the composition to read clearly.
for i in range(1, rows + 1): — Program 7: apex to waist.
for i in range(rows - 1, 0, -1): — Program 8 style: skip duplicate waist.
Left j = rows..1 and right k = 2..rows with i == j / i == k on every row.
Each line is 2 * rows - 1 chars; total lines = 2 * rows - 1.
O(n²) time for n = rows, O(1) extra space. Waist printed once.
rows = 4Seven printed lines: upper i = 1..4, then lower i = 3..1 (width = 7).
| Phase | i | Stars | Printed row |
|---|---|---|---|
| Upper | 1 | 1 (apex) | * |
| Upper | 2 | 2 | * * |
| Upper | 3 | 2 | * * |
| Upper | 4 | 2 (waist) | * * |
| Lower | 3 | 2 | * * |
| Lower | 2 | 2 | * * |
| Lower | 1 | 1 (tip) | * |
If the lower loop started at i = 4, the waist would appear twice — that is the key off-by-one.
Where this hollow diamond (and half-stacking) shows up beyond the homework prompt.
Build complex shapes from known halves.
Example: assign Program 7 then “add the mirror.”
Outline vs solid star runs side by side.
Example: Program 10.
DRY the duplicated leg loops once halves click.
Example: Example 3 above.
Start lower at rows on purpose, then fix to rows - 1.
Example: spot the double waist visually.
Swap * for # or digits at match positions.
Example: print i on the diagonals.
Pair with input validation and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: say “Program 7, then Program 8 from rows - 1” before writing a single loop — that is the whole design.
Why the hollow diamond is a favorite series capstone.
No new diagonal formulas — only stacking.
A double waist is obvious when the lower loop is wrong.
Same half idea; Program 10 changes how cells fill.
Extract print_row once the structure is clear.
Pro Tip: master the duplicated-loop version first; extract a helper only after both halves look correct.
Small habits that keep hollow-diamond code clean.
rows - 1Starting at rows duplicates the waist.
k Starting at 2Preserves single apex/tip stars on i == 1 rows.
int(input()) in try/exceptAvoid crashes when the user types letters instead of a number.
Skipping the else branch collapses columns and ruins the diamond.
Trace rows = 4 (7 lines) before larger demos.
Pro Tip: if two identical widest rows appear in the middle, you almost certainly started the lower loop at rows.
Mistakes that commonly break hollow diamonds.
rowsDuplicates the widest row in the middle.
→ Use for i in range(rows - 1, 0, -1):.
i != j && i != k does not magically fill the diamond.
→ For a solid diamond, use Program 10’s space/star formulas.
Columns collapse; the outline becomes a smear.
→ Always print " " when the equality fails.
Right-side padding keeps width 2n-1; trimming breaks alignment.
→ Let both inner loops finish every row.
Letters or empty input throw ValueError.
→ Catch ValueError and re-prompt on failure.
Check these inputs before calling the solution done.
Upper prints one apex; lower (i = 0) never runs — one line total.
Both outer loops skip — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
2n-1 lines and width — may wrap on tiny terminals.
int(input()) raises ValueError — validate first.
i == rows onceOnly the upper loop should print the widest row.
Try these variations to lock in the pattern.
rows, see the double linerows - 12*i-1 stars2 * rows - 1 for this construction.rows is half-height to the waist, not the total printed line count.rows > 0 for interactive programs; rows = 1 prints a single star.Quick Takeaway: print Program 7, then Program 8 from rows - 1 — that is the hollow diamond.
| Program | Time | Extra space |
|---|---|---|
| Two outer loops (Examples 1–2) | O(rows²) | O(1) |
| Helper + ternary (Example 3) | O(rows²) | O(1) |
About 2n - 1 lines, each with Θ(n) cell visits across left + right blocks.
The hollow diamond is composition: Program 7’s inverted V plus Program 8’s V from rows - 1, sharing the same diagonal legs. Skip the duplicate waist, and the outline closes cleanly — then move on to a filled diamond if you want solid stars.
Practice the three examples above, then continue to the filled diamond.
Upper then lower, waist once, width = 2n−1 — keep the shared legs, and validate row counts when reading input.
rows - 1” before codingj/k bodies on both halves2 * rows - 1try/except ValueError for interactive demosi == rowsi != j alone to fill the diamondrows = 1 single-star edge casePrint the outline the beginner-friendly way.
Stack two hollow Vs
Definitioni = 1..rows
Prog 7i = rows-1..1
Prog 8Print once
SeamO(n²) time
AnalysisSame half-stacking idea, but with solid centered star runs instead of a hollow outline.
12 people found this page helpful