A method that adds two numbers is useful. A method that adds any quantity of numbers is far more useful, because it covers the first task and many others. Moving between a narrow task and a broad one is a basic skill in problem solving.
A General Problem
A general problem covers a broad range of valid inputs. "Find the largest value in a non-empty list of numbers" is general: it allows lists of any length and any values.
A Special Case
A special case is obtained by adding a restriction to a general problem. "Find the larger of two numbers" is a special case of the problem above, because the list is now restricted to exactly two values.
Definition: Special case. A narrower form of a problem obtained by adding one or more restrictions to its inputs.
A special case is usually easier to solve. To find the larger of two numbers, a single comparison is enough. That simple solution does not carry over to a list of one hundred values, because it depends on the restriction that only two values exist.
Generalizing a Problem
The reverse process is called generalization.
Definition: Generalization. The process of removing restrictions from a problem so that it covers a wider range of inputs.
A solution to the generalized problem can be used for every instance of the original problem and for many others.
Table 1.2: Special cases and their generalizations
| Special case | Restriction used | General problem |
|---|---|---|
| Larger of two numbers | Exactly two values | Largest value in a list |
| Sum of the first 10 natural numbers | n is fixed at 10 | Sum of the first n natural numbers |
| Search in a sorted list | Values are in order | Search in any list |
| Area of a square | Length equals breadth | Area of a rectangle |
Using Special Cases Wisely
Special cases are valuable in two ways. First, solving a simple special case often shows how the general solution should work. A student who understands how to find the larger of two numbers can extend the idea: keep the larger value seen so far and compare it with each new value. Second, a special case may permit a faster method. A sorted list can be searched much more quickly than an unsorted one, as Unit IV shows.
The danger lies in forgetting which restriction a solution depends on. A method designed for a sorted list cannot assume that an unsorted list has the same useful order. Before a solution is reused on a broader problem, the restrictions it relies on must be checked.
Example 1.2: From a special case to a general solution
Problem: A solution exists for "find the larger of two numbers a and b". Extend it to find the largest of the values 12, 7, 19, 4.
Solution:
- Start with the first value as the largest so far: 12.
- Compare with 7. The larger of 12 and 7 is 12.
- Compare with 19. The larger of 12 and 19 is 19.
- Compare with 4. The larger of 19 and 4 is 19.
Result: The largest value is 19. The two-number solution was applied repeatedly, which solves the general problem for a list of any length.
Common mistakes
- Applying a special-case solution to a general problem without checking the restriction it depends on.
- Generalizing so far that the problem no longer has a clear input and output.
- Assuming that every list is sorted, non-empty or free of repeated values when the problem does not say so.
Key takeaways
- A special case adds a restriction; generalization removes restrictions.
- A general solution works for all the special cases it contains.
- A special-case solution may be simpler or faster but is valid only under its restriction.
- Solving a small special case first is a good way to discover the general method.
Practice questions
- Is "find the sum of three numbers" a special case or a generalization of "find the sum of n numbers"?
- Name the restriction that makes "area of a square" a special case of "area of a rectangle".
- Why might a programmer deliberately solve a special case?
Answers to the practice questions
- It is a special case, because n is restricted to 3.
- The length and the breadth must be equal.
- It may be simpler or faster, and it often reveals the idea needed for the general solution.
Sources
- Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit I
