## Inverted Half Left Star Pyramid

Back to Programming

### Description

Inverted Half Pyramid Left

*****

****

***

**

*

For printing the pattern, the number of lines is taken as input. One outer for loop and two inners for loops are used to print the pattern here. The outer for loop is used to count the number of lines in the reverse order as the number of stars decreased and to make a relationship between the line number and the number of stars it has been written in the reversed order. The first inner for loop is used to print the number of spaces and the loop executes from 1 to n-i to print the spaces. The 2nd inner for loop is used to print the stars and the loop executes for 1 to i for each i.

### Algorithm

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

## Time Complexity:

for(i=n;i>=1;i--)--------------------------------------- n

{

//printing the spaces

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

printf(" ");

//printing the stars

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

printf("*");

printf("\n");

}

The first ‘for’ loop is running from n to 1 and the inner for loop is running from 1 to n-i and the second loop is from 1 to i. so the time complexity is O(n*(n-i+i))=O(${\mathrm{n}}^{2}$).