AlgoDaily

Shapes and Patterns

Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.

From Counts To Shapes

Welcome back, Pattern Explorer!

In Introduction to Numbers and Counting, you learned that numbers help us name how many things we have.

Now we are ready for the next idea: what kind of things we have and how they are arranged.

A computer can count objects, but for data science, AI, and machine learning, it also needs to notice things like:

  • Is this object round or pointy?
  • Does this picture have straight lines?
  • Does this sequence repeat?
  • Do these things look similar?

That is why shapes and patterns matter. They are some of the first clues computers use to understand the world.

From Counts To Shapes

What Is Shape

A shape is an object's form

A shape tells us what something looks like on the outside.

Think of it like describing a cookie:

  • A circle is round.
  • A triangle has 3 sides and 3 corners.
  • A square has 4 equal sides and 4 corners.
  • A rectangle has 4 sides and 4 corners, but it can be longer in one direction.

We can describe shapes using simple clues called features.

Important shape features include:

  • Sides: straight edges around the shape
  • Corners: pointy meeting places
  • Curves: round parts
  • Size: small, medium, large
  • Color: red, blue, green, and so on

In machine learning, a feature is a clue we give to the computer. For shapes, sides and corners are very useful clues.

What Is Shape

Find The Feature

A computer wants to tell whether a shape is a triangle.

Which feature is most helpful?

Shapes As Data

Computers need descriptions

A computer does not magically “see” a triangle the way we do.

We give it data, like:

  • name: triangle
  • sides: 3
  • corners: 3
  • has curves: no

Then the computer can use these clues to make decisions.

Here is a tiny Python example. We describe shapes using dictionaries, then let Python guess the shape name from the number of sides.

```python
shapes = [
    {"sides": 0, "corners": 0, "has_curves": True},
    {"sides": 3, "corners": 3, "has_curves": False},
    {"sides": 4, "corners": 4, "has_curves": False}
]

for shape in shapes:
    sides = shape["sides"]

    if sides == 0 and shape["has_curves"]:
        name = "circle"
    elif sides == 3:
        name = "triangle"
    elif sides == 4:
        name = "square or rectangle"
    else:
        name = "unknown shape"

    print("Shape data:", shape, "=>", name)
```

Patterns Repeat

A pattern is a rule you can notice

A pattern happens when things follow a rule.

For example:

red, blue, red, blue, red, blue

The rule is: red, then blue, then repeat.

Patterns can use many kinds of things:

  • colors: red, blue, red, blue
  • shapes: circle, square, circle, square
  • sizes: small, big, small, big
  • sounds: clap, tap, clap, tap
  • positions: up, down, up, down

In AI, finding patterns is a huge idea. A model learns by noticing repeated clues in data.

Patterns Repeat

Complete Pattern

Complete the pattern:

circle, square, circle, square, ___

Type the missing word.

Fill in the blank: _____________

Python Spots Patterns

A pattern has a repeating unit

The smallest part that repeats is called the pattern unit.

For this pattern:

circle, square, circle, square, circle, square

The repeating unit is:

circle, square

Python can help us check whether a list follows a repeating unit.

```python
pattern = ["circle", "square", "circle", "square", "circle", "square"]
unit = ["circle", "square"]

matches = True

for index in range(len(pattern)):
    expected = unit[index % len(unit)]
    actual = pattern[index]

    print("Position", index, "expected", expected, "and saw", actual)

    if actual != expected:
        matches = False

print("Does the pattern match the unit?", matches)
```

Only Number Patterns

True or false?

A pattern must always be made of numbers.

Pictures Have Patterns

Images are shape-and-color patterns

A picture on a computer is made of tiny squares called pixels.

If we zoom in far enough, an image can look like a grid:

⬜ ⬜ ⬛ ⬜ ⬜
⬜ ⬛ ⬛ ⬛ ⬜
⬛ ⬛ ⬛ ⬛ ⬛
⬜ ⬜ ⬛ ⬜ ⬜
⬜ ⬜ ⬛ ⬜ ⬜

Your eyes may see an arrow shape. A computer sees many tiny squares with colors.

This is one reason shapes and patterns are important for AI:

  • A face has patterns of eyes, nose, and mouth.
  • A car has patterns of wheels, windows, and edges.
  • A handwritten letter has patterns of curves and lines.

The computer learns to connect these tiny clues to bigger meanings.

Pictures Have Patterns

Shape Sorting Practice

You have these shape clues:

sides: 4
corners: 4
curves: no

Which answer best matches the clues?

Why AI Cares

Shapes and patterns are early AI building blocks

Today you learned that:

  • Shapes can be described using features.
  • Features are clues, like sides, corners, curves, color, and size.
  • Patterns follow rules.
  • A repeating pattern has a pattern unit.
  • Computers can use shape and pattern clues to understand data.

This is the beginning of a powerful idea: computers can learn from clues.

In later lessons, we will use numbers in new ways, but keep this picture in your mind: data is often a collection of tiny clues, and learning means finding useful patterns in those clues.

Why AI Cares

Open interactive view →