A shopkeeper who wants to know the day's total sales, a teacher who wants the highest mark in a class and a traveller who wants the shortest route all face problems. In computing, the word problem has a precise meaning, and understanding that meaning is the first step towards solving anything with a computer.
What Is a Problem?
A problem is a task with a goal. In computing, a problem states what information is given and what result is required. The given information is called the input, and the required result is called the output. A problem may also state rules that the input or the output must obey. Such a rule is called a constraint.
Definition: Computational problem. A problem that can be described completely in terms of its inputs, the required outputs and the relationship between them, so that it can be solved by a finite sequence of steps.
Consider the task "find the largest mark in a class". The input is a set of marks. The output is one value: the largest mark in that set. A constraint might be that every mark lies between 0 and 100.
What Is a Problem Instance?
A problem is stated in general terms. It does not mention particular values. When actual values are supplied for the input, we obtain a problem instance.
Definition: Problem instance. One particular case of a problem, obtained by giving actual values to its inputs.
The problem "find the largest number in a list" has an unlimited number of instances. The list 8, 15, 6, 11 is one instance, and its answer is 15. The list 3, 3, 3 is another instance, and its answer is 3. The rule of the problem stays the same while the values and the answer change from instance to instance. Table 1.1 separates the two ideas.
Table 1.1: Difference between a problem and a problem instance
| Aspect | Problem | Problem instance |
|---|---|---|
| What it describes | The task in general | One particular case of the task |
| Input | Described by type and rules | Actual values |
| Number | One statement | Many possible instances |
| Example | Find the largest number in a list | Find the largest of 8, 15, 6, 11 |
Why the Distinction Matters
A solution is written for the problem, not for one instance. A method that produces the correct answer for 8, 15, 6, 11 is not necessarily correct for every list. It might fail when the list has one value, when all values are equal, or when the largest value is in the last position.
For this reason a solution is always checked against several different instances. Good instances to try include a very small case, a case with repeated values and cases at the limits of the allowed range. These are called boundary cases, and many errors in programs are found only when boundary cases are tried.
Parts of a Well-Stated Problem
A well-stated problem answers three questions:
- What is given? This identifies the inputs, with their types and allowed ranges.
- What is required? This identifies the outputs and their form.
- What rules apply? This identifies the constraints and the relationship between input and output.
If any of the three answers is missing, the problem is incomplete, and different people may solve different problems while believing they are solving the same one.
Example 1.1: Identifying the parts of a problem
Problem: A teacher wants to know the average mark of a class test marked out of 50.
Solution:
- Input: the marks of all students who took the test.
- Constraint: each mark is a whole number from 0 to 50, and there is at least one mark.
- Output: one number, the sum of the marks divided by the number of marks.
- One instance: the marks 40, 35, 45. The sum is 120 and the count is 3.
Result: For this instance the output is 120 / 3 = 40.
Common mistakes
- Treating one worked instance as proof that a method solves the whole problem.
- Starting to write a solution before the inputs, outputs and constraints have been written down.
- Forgetting the constraints, for example allowing an empty list when the task needs at least one value.
Key takeaways
- A problem states the task; an instance supplies actual input values.
- Every computational problem has inputs, outputs and, usually, constraints.
- One problem has many instances, and a solution must work for all valid instances.
- Boundary cases are the instances most likely to reveal errors.
Practice questions
- State the input and output of the problem "count the vowels in a word".
- Give two different instances of the problem "find the smaller of two numbers".
- Why is testing one instance not enough to trust a solution?
Answers to the practice questions
- Input: one word. Output: a whole number giving how many of its letters are vowels.
- Any two pairs, for example (4, 9) with answer 4 and (7, 2) with answer 2.
- A solution must work for every valid instance, and one instance cannot show how it behaves on other values or on boundary cases.
Sources
- Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit I
