**Introduction**

We must’ve seen the rainbow and wondered how beautiful it is. The pattern of colours **starts with red on the outside and changes through orange, yellow, green, blue, indigo to violet on the inside**.

So what is precisely a pattern? A pattern is a regularity in the world, in human-made design, or in abstract ideas. As such, the elements of a pattern repeat predictably.

As we begin to connect patterns in nature and life, they bring a sense of harmony to our minds. Patterns lead to and build math, vocabulary, and cognitive concepts.

In simple words, a Pattern is “ a consistent, recurring characteristic that helps us identify a phenomenon and predict its future behaviour.”

For example:

Suppose I start saying aloud the numbers **2, 4, 6, 8** and then suddenly stop and ask you to continue. What will you say first?

** 2,4,6,8,10**……Right? Why so?

You have noticed that these are even numbers. Once your brain has picked up this behaviour, you understand what is happening, and you see that it is consistent. As a result, you can predict its future behaviour and flow.

It is precisely the meaning of a “Pattern.”

Let’s take some more examples:

**Ans: 11**

Wonder how?

Now, it’s your turn, Ninja, to solve the below questions

Before we move on in the article, it is quite important to mention that this topic will be covered in a total of 4 different parts with this one being part – 1.

The rest of the articles in this series are:

- Basic Pattern Problems | Part – 2
- Intermediate Level Pattern Problem | Part – 3
- Advanced Pattern Problems | Part – 4

The topic needs a detailed discussion to touch all the aspects of Mastering Pattern Problems. In this part, we will see different patterns that exist around us. We will also walk you through “How to approach the pattern problems in programming”.

## Patterns in Mathematics

Patterns are everywhere!

Let’s discuss them in the Modern World of Mathematics.

*The pattern is “ a consistent, recurring characteristic that helps us identify a phenomenon and predict its future behaviour.” *

Have a look at the formulas for calculating the nth term:

- nth- term formula for a Sequence.
- Find the first 5 terms of the Sequence
- a(n) = 3n^2 + n

- Find the first 5 terms of the Sequence

- Term-1
- n=1, a(1) = 3(1)(1) + 1 = 4

- Term-2
- n=2, a(2) = 3(2)(2) + 2 = 14

- Term-3
- n=3, a(3) = 3(3)(3) + 3 = 30

- Term-4
- n=4, a(4) = 3(4)(4) + 4 = 52

- Term-5
- n=5, a(5) = 3(5)(5) + 5 = 80

The nth term of an arithmetic sequence:

a(n) = a(1) + (n – 1)d

Where, a(1) = First Term

d = Common difference

E.g,

4, 10, 16, 22, 28, ……….?

Now, from the above equation, we can find any nth number of the sequence. Let’s assume I want the 7th term, which means here n equals 7.

a(7) = 6(7) – 2

= 42 – 2

= 40

Try to solve these questions with the help of the above formula:

- What is the nth term formula for the number of tiles in the nth figure of the sequence?
- How many tiles will be in the Eight(8) figure of the Sequence?
- Which figure will exactly consist of 320 tiles?

**Pattern in Fibonacci Sequence**The Fibonacci sequence is the series of numbers such that the next number is found by adding up the two numbers before it.

Fib(n) = Fib(n-1) + Fib(n-2)

Where,

Fib(n) is term “n”

Fib(n-1) is the previous term (n-1)

Fib(n-2) is the term before that (n-2)

Image Source: Google

Find the 10th term in the fibonacci sequence.

Fib(10) = Fib(10-1) + Fib(10-2)

= F(9) + F(8)

= 34 + 21

= 55

**How to approach the Pattern Problems in Programming?**

**Pattern Problems in Programming:** Pattern, as the name suggests, is the recurring sequence with a consistent manner. A **pattern** is an all-purpose solution that can be repeated time and again to a frequently occurring problem.

**Note: **Each task in the pattern problems comes with **input format** and **output format** to assist you in writing a conventional code to get the desired output.

There’s a need to understand the basics and learn the tricks to answer any random pattern question. Initially, it may seem quite mystifying and appear challenging, however, intrinsically, patterns are not that entangled as it provides a convenient way to identify and code to create a proper and methodically designed pattern.

We’ll Master Pattern Problems in this lesson only. So, keep grinding!

**Star Patterns:**

Image Source: Medium

**Number Patterns:**

**Character Patterns:**

Image Source: Google

Image Source: Google

That was your reaction, right? See, I caught you. Okay, let’s master the tricks for making these beautiful patterns.

**Pre-requisites:** Deep knowledge of Loops like for loop, while loop, and do-while loop as we’ll be using the loops throughout the lesson to Master in Pattern Problems.

Let’s take a look at Half Pyramid Star Pattern:

**The algorithm says:**

- Initialise two variables named i and j with 0, i will point to the row index, whereas j will point to the column index.
- Initialise the outer loop, add the condition [ i < no_of_rows ], here no_of_rows is 5 and increment i^ th index by 1.
- Initialise the inner loop, add the condition [ j <= i ] and increment j^th index by 1. Add the [“\n”] outside the inner for loop so that it can jump to the next line.

Iteration 1:

- i=0, 0<5 True
- j=0 , 0 <= i, where i is 0, further execute the inner statement.

* |

- After printing, j->j+1 i.e; 0+1=1, Now again check the condition, 1<=0, it is False. Now it will terminate the inner loop and increment the ith value by 1. What if the condition would be like this [ j< no_of_coloumns], no_of_coloumns is 5. Then, “*” would get printed no_of_coloumns -1 times, which will ultimately form a rectangle pattern.

Iteration 2:

Iteration 3:

Iteration 4:

Iteration 5:

At i=5, the outer loop will terminate.,

**Pseudo Code**:

```
n = input (“Enter the number of rows:”)
while row < n
while col <= row
print “ * “ and space
cols = cols + 1
end
rows = rows + 1
```

## Frequently Asked Questions

**What is an example of a pattern in math?**

In Mathematics, a pattern is a repeated arrangement of numbers, shapes, colours and so on. Few examples of numerical patterns are:

Even numbers pattern -: 2, 4, 6, 8, 10, 1, 14, 16, 18, … Odd numbers pattern -: 3, 5, 7, 9, 11, 13, 15, 17, 19, … Fibonacci numbers pattern -: 1, 1, 2, 3, 5, 8 ,13, 21, … and many more.

**How do you identify a pattern?**

Suppose we have some numbers 5, 4, 7, 8, 6, 5, ….and if I want you to predict the next one, what will you say? Confused? Because it is not a pattern, what if we have another set of numbers 2, 6, 10, 14, 18,…? Now you can easily predict the following number as here is the “consistency” of the numbers.

**How to Master in Pattern Problems?**

There’s only a need to understand the basics and learn the tricks to Master in Pattern Problems. By practising, you will be able to think about logic. Once you encounter any single pattern, you will be able to solve any random pattern. To gain an in-depth understanding, read the rest of the articles in this series.

**Where are patterns used in real life?**

Repeating patterns can be found in nature and everyday life. Patterns are present in architecture, clothing, multiplication tables, and even on the bottom of your shoes!

## Key Takeaways

In conclusion, patterns are the sequence of numbers, characters, data, and so on. Approaching the pattern problems in the right way is all it takes. Every problem needs to decompose into the smallest possible fragments. This way, anyone can Master Pattern Problems.

The goal is not just to mug up these patterns but to improve the logical thinking process. Do not stop here; here is the guided path which you can follow to enhance your coding skills in every aspect. We have a variety of top-notch courses from the best teachers.

To Master in Pattern Problems, read the next article on Basic Pattern Problems | Part – 2.

Happy Learning Ninja!

**By Alisha Chhabra**

## Leave a Reply