# Algorithms == Patterns

Patterns lie at the heart of algorithms. If we think of an algorithm as a method for problem solving distilled to the simplest and perhaps fastest form, pattern recognition allows us to achieve that simplicity. The resulting algorithm is itself a set of patterns. Finding and using patterns when creating algorithms is a skill useful in all walks of life, since we are constantly looking for shortcuts. Google Education identifies pattern recognition and generalization as a core computational thinking skills, used to determine how to interact with others, when to buy stocks at the cheapest price, or solve math problems quickly.

More complex areas where algorithms can be used to recognize or create patterns:

A simple way of dealing with patterns in computer science is the notion of a loop. In an introductory programming class, students will explore different types of loops such as the for loop, used to repeat a block of instructions a certain number of times. For instance, if we were instructing Billy on how to hand out cupcakes to a class of 30, rather than repeatedly tell him to:

```give cupcake to student 1
give cupcake to student 2
…
give cupcake to student 30```

We recognize he will be doing the same thing 30 times, so could instead say:

```for(student_number = 1; student_number <= 30; student_number++)
{
give cupcake to student with student_number
}```

The statements between the parentheses instruct that at the start of the loop, begin with student_number 1. Each time you go through the loop, add 1 to the student number (student_number++ is a shortcut for student_number = student_number + 1). Keep going through the loop as long as student_number is less than or equal to 30, so once it hits 31, the loop will end.

Understanding that hardly seems easier than just writing out 30 lines of instructions, but some more recent programming languages make it even easier by approximating natural language:

```for(each student in classroom)
{
give cupcake to current student
}```

Which is exactly the way we would think of it in real life, since without necessarily realizing it, we’ve created a loop in our head. Thinking about patterns through loops may make algorithms more accessible, which is the ultimate goal of this project.