An algorithm is a sequence of steps followed to solve a problem. Before writing one, the problem must be defined clearly, and the input and output must be identified. An algorithm needs a limited number of exact steps. If it enters an endless loop, it breaks the finiteness property and is not a valid solution.
Algorithms can be shown with flowcharts. In a flowchart, a diamond shape represents a decision, and a rectangle represents a process step. Definiteness means that for the same input, the algorithm follows the same path every time it runs.
A practical way to check an algorithm is to trace each step with a small input, record the intermediate values, and compare the final result with the expected answer before using it on larger inputs.
Inside your account
What an account adds to the pages you are reading.
Lessons
Topic explanations with worked examples, split into units.
An algorithm is a sequence of steps for solving a problem.
A flowchart uses a diamond for decisions and a rectangle for processes.
An algorithm must contain a limited number of precise steps (finiteness).
Definiteness requires the same path for the same input.
Input and output should be determined before writing the algorithm.
Example
Question: what is the result of an algorithm that finds the sum of all numbers from 1 to 10? Multiplying 10 by 11 gives 110, and dividing by 2 gives 55. The result is 55.
Question: a loop repeats 5 times, and each pass performs 2 operations. How many operations are performed in total? Five repetitions with two operations each give 10 operations.
Common mistakes
Writing a loop with no way to end. A loop that never stops breaks the finiteness requirement.
Writing vague steps that can be read in more than one way. Each step should be exact so that the same input gives the same result.
Starting to write code before defining the problem, input and output. Clear definitions come first.
Summary
An algorithm is a finite, precise and definite sequence of steps that solves a problem. Flowcharts make the steps visible, with diamonds for decisions and rectangles for processes. Defining the problem, input and output before writing the steps prevents most errors.
Tracing a short example by hand before relying on the result is a useful habit, because it reveals missing steps and endless loops early.