## Hollow Rhombus Star Pattern

Back to Programming

### Description

Hollow Rhombus Star Pattern

For printing the aforesaid pattern the number of lines is taken as input. The first inner for loop is used to print the spaces before the star at each line. The second inner for loop is used to print the stars of each line. the stars are only printed at the boundary line of a rhombus.

### Algorithm

``````INPUT: the number of lines
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: [taking the input]
Step 2: [printing the pattern]
For i=1 to n repeat
For j=1 to n-I repeat
Print " "
[End of ‘for’ loop]
For k=1 to n repeat
If i=1 or i=n or k=1 or k=n then
Print "*"
Else
Print “ “
[End of ‘for’ loop]
Move to the next line
[End of ‘for’ loop]
Step 3: Stop.
``````

## Time Complexity:

for(i=1;i<=n;i++)-------------------------------------- n

{              //printing the spaces

for(j=1;j<=n-i;j++)-------------------------- n-i

printf(" ");

//printing the stars

for(k=1;k<=n;k++)-------------------------- n

{             if(i==1||i==n||k==1||k==n)

printf("*");

else

printf(" ");

}

printf("\n");    }

The complexity is: O(n*(n-i+n))=O(${\mathrm{n}}^{2}$)