Once a problem has been analysed, the solution must be written as a series of steps so clear that they can be followed without further thought. Such a series of steps is called an algorithm.

What Is an Algorithm?

Definition: Algorithm. A finite sequence of clear, unambiguous steps that, when carried out on valid input, produces the required output and then stops.

An algorithm is not a program. It is a plan, written in plain language, that can later be translated into any programming language. Writing the algorithm first keeps attention on the logic of the solution rather than on the grammar of a language.

Characteristics of a Good Algorithm

Every algorithm is expected to have the properties listed in Table 1.5.

Table 1.5: Characteristics of an algorithm

Characteristic Meaning
Input It takes zero or more clearly specified inputs
Output It produces at least one result
Definiteness Each step has exactly one meaning
Finiteness It stops after a limited number of steps
Effectiveness Each step is simple enough to be carried out

Building the Steps from the Requirement

An algorithm is developed by working from the requirement:

  1. Write down the inputs and the required output.
  2. Decide what must be calculated or decided to get from one to the other.
  3. Arrange these actions in an order in which every value is available before it is used.
  4. Make sure the last step produces the output and the process stops.

For the task of totalling three numbers, the algorithm is as follows.

Algorithm: Sum of three numbers
Input:  three numbers a, b, c
Output: their sum
Step 1: Start
Step 2: Read a, b, c
Step 3: Set total = 0
Step 4: Set total = total + a
Step 5: Set total = total + b
Step 6: Set total = total + c
Step 7: Display total
Step 8: Stop

Flowchart symbols are studied in detail in Unit II.

Checking the Plan by Tracing

An algorithm is checked by tracing: carrying out the steps by hand on a small instance and recording the value of each variable after every step. If a step uses a value that has not yet been read or calculated, the plan is incomplete. If the final value differs from the expected answer, a step is wrong.

Example 1.5: Tracing an algorithm

Problem: Trace the algorithm "Sum of three numbers" for the input 4, 7, 2.

Solution:

  1. After Step 2: a = 4, b = 7, c = 2.
  2. After Step 3: total = 0.
  3. After Step 4: total = 0 + 4 = 4.
  4. After Step 5: total = 4 + 7 = 11.
  5. After Step 6: total = 11 + 2 = 13.
  6. Step 7 displays 13.

Result: The output is 13, which agrees with 4 + 7 + 2 = 13 worked by hand.

Common mistakes

  • Writing a step that can be understood in more than one way, such as "process the numbers".
  • Using a variable before it has been given a value.
  • Leaving out the stopping step, or writing a repetition that never ends.

Key takeaways

  • An algorithm is a finite sequence of clear steps that solves a problem.
  • Its characteristics are input, output, definiteness, finiteness and effectiveness.
  • The logic is planned in plain language before any program code is written.
  • Tracing a small instance by hand is the simplest check of an algorithm.

Practice questions

  1. Which characteristic requires that an algorithm must stop?
  2. Why is an algorithm written before the program?
  3. What does tracing an algorithm mean?

Answers to the practice questions

  1. Finiteness.
  2. It lets the logic be planned and checked without being tied to the rules of one programming language.
  3. Carrying out its steps by hand on a small input and recording the value of each variable after every step.

Sources

  • Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit I