Study guide

What Is an Algorithm? Programming Basics for Beginners

A beginner-friendly explanation of algorithms: what they are, everyday examples, sequence, selection and loops, flowcharts and pseudocode, and searching and sorting.

Every app, website and game runs on algorithms. The word sounds technical, but the idea is something you use every day. Understanding algorithms is the first step towards learning to program, and it is a common topic in computer awareness exams.

What is an algorithm?

An algorithm is a precise, step-by-step set of instructions for solving a problem or completing a task. A good algorithm is:

  • Clear: each step has only one meaning.
  • Finite: it finishes after a limited number of steps.
  • Effective: each step can actually be carried out.
  • Correct: it produces the right result for every valid input.

The word comes from the name of the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi, whose books helped spread the Hindu-Arabic number system and methods of calculation.

Everyday algorithms

A recipe is an algorithm for cooking a dish. Directions to a friend's house are an algorithm for getting there. Even the steps for making a cup of tea can be written as one:

  1. Fill the kettle with water and switch it on.
  2. Put a tea bag in a cup.
  3. When the water boils, pour it into the cup.
  4. Wait three minutes, then remove the tea bag.
  5. If you like milk, add milk.

Computers need instructions that are even more exact, because they cannot guess what you mean.

Three building blocks

Almost every algorithm is built from three basic structures:

StructureMeaningTea example
SequenceSteps carried out in orderFill kettle, then add tea bag
SelectionA decision: if a condition is true, do one thing, otherwise do anotherIf you like milk, add milk
Iteration (loop)Repeating steps until a condition is metKeep waiting until the water boils

Flowcharts and pseudocode

Before writing code, programmers often plan an algorithm using a flowchart, a diagram with standard shapes: ovals for start and end, rectangles for actions, diamonds for decisions and arrows for the direction of flow.

Another method is pseudocode, which describes the steps in plain, structured language rather than a real programming language. For example, to find the largest number in a list:

set largest to the first number
for each remaining number in the list:
  if the number is greater than largest, set largest to the number
output largest

Searching and sorting

Two of the most famous types of algorithm are for searching and sorting:

  • Linear search checks each item one by one. It is simple but slow for long lists.
  • Binary search works on a sorted list. It checks the middle item, then discards the half that cannot contain the target, and repeats. Searching 1,000 sorted items takes at most about 10 checks, because each step halves the list.
  • Sorting algorithms such as bubble sort, merge sort and quicksort put items in order. Some are much faster than others on large amounts of data.

Comparing how quickly algorithms work as the amount of data grows is a key part of computer science.

From algorithm to program

A program is an algorithm written in a programming language such as Python, C or Java so that a computer can run it. Learning to break problems into clear steps is the most important programming skill of all, whatever language you choose.

Test your knowledge of programming and computers with the quizzes below.

Put it into practice

Programming and Networking Basics

Computer · Medium · 10 questions

Computer Fundamentals Quiz

Computer · Easy · 10 questions

Number Sense and Arithmetic

Mathematics · Easy · 10 questions

More articles

The Seven Continents at a Glance

A quick guide to the seven continents: their size, population, famous features and key facts about Asia, Africa, the Americas, Antarctica, Europe and Australia.

30 November 2026 · 6 min read

How Satellites Stay in Orbit

Why satellites do not fall to Earth, the difference between low Earth and geostationary orbits, what satellites do for us, and key milestones from Sputnik to ISRO.

29 November 2026 · 6 min read