Problem solving is the process of identifying a problem, understanding it completely, and designing a well-defined sequence of steps to arrive at a solution. In computer science, problem solving is the fundamental activity that precedes programming. A computer is merely a tool; it is the human mind that analyses a problem and devises an algorithm that the computer can execute. This chapter presents the systematic steps of problem solving and the tools used to express solutions: algorithms, pseudocode and flowcharts.
Unlike everyday problems, computer-based problems must be solved with absolute precision and completeness because a computer executes instructions literally. A single wrong step or a missing case can lead to incorrect output. Therefore, problem solving in computing demands clarity of thought, careful analysis of inputs and expected outputs, and rigorous testing of the solution. The skills developed here, breaking a large problem into smaller subproblems, generalising, and verifying results, are valuable not only in programming but in every analytical discipline.
The chapter begins with the general steps of problem solving, moves on to the concept and characteristics of an algorithm, then introduces pseudocode and flowcharts with examples, and finally shows how a solution is translated into a program and tested. Understanding these foundations is essential before writing the first Python program, because a good program always starts with a good algorithm.
Solving a problem with a computer typically follows these steps:
The analysis phase is the most important. A student who rushes to write code without understanding the problem will waste time and produce incorrect results. To analyse a problem properly, we must determine the input (the data given to the program), the process (what computations or decisions must be made) and the output (the result the program must produce). This is often summarised as the IPO model.
For example, consider the problem "Find the largest of three numbers". The inputs are three numbers; the process involves comparing them; the output is the largest value. If the problem is misunderstood, for instance if the user expects the second largest number, the solution fails even though the code runs without error. Good problem analysis also considers boundary and special cases, such as equal numbers, negative values, or empty input.
Every meaningful problem can be described by specifying its inputs and outputs clearly. This clarity allows the algorithm designer to decide the data structures and steps required, and later allows the tester to create appropriate test cases.
An algorithm is a finite set of well-defined instructions that, when followed step by step, accomplishes a specific task. Algorithms can be expressed in natural language, in pseudocode, or as flowcharts; they are independent of any programming language. A recipe for cooking and a manual for assembling furniture are everyday examples of algorithms.
For an algorithm to be valid, it must have the following characteristics:
Pseudocode is a compact, informal way of describing an algorithm using a mixture of natural language and programming-language-like constructs. It is not executable, but it is easier to read than a flowchart and easier to translate into actual code than plain English. Pseudocode commonly uses keywords such as INPUT, OUTPUT, IF...ELSE, WHILE, FOR and RETURN.
For example, a pseudocode algorithm to find the largest of three numbers is:
INPUT a, b, c
IF a >= b AND a >= c THEN
largest = a
ELSE IF b >= a AND b >= c THEN
largest = b
ELSE
largest = c
OUTPUT largest
Pseudocode helps a programmer think through the logic before writing real code, and it can be shared and discussed without worrying about the syntax of a particular language.
A flowchart is a graphical representation of an algorithm. It uses standard symbols connected by arrows to show the flow of control. The main flowchart symbols are:
Flowcharts make the structure of an algorithm visible at a glance, which is helpful for finding logical errors and for communicating the solution to others. However, drawing flowcharts for very large programs becomes cumbersome, which is why pseudocode and actual code are preferred for big projects.
To find the factorial of a number n, we start, read n, initialise fact = 1 and i = 1, then repeatedly multiply fact by i and increment i while i <= n, and finally print fact. This logic is shown diagrammatically in a flowchart using the symbols above.
The following are classic examples that every class 11 student should master.
A prime number has exactly two distinct factors: 1 and itself. To check whether a given number n is prime:
Step 1: START
Step 2: INPUT n
Step 3: IF n <= 1 THEN OUTPUT "Not prime" and STOP
Step 4: FOR i = 2 to n/2
IF n % i == 0 THEN OUTPUT "Not prime" and STOP
Step 5: OUTPUT "Prime"
Step 6: END
If any number from 2 to n/2 divides n evenly, n is composite; otherwise it is prime.
To reverse a three-digit number such as 347:
Step 1: START
Step 2: INPUT num
Step 3: rev = 0
Step 4: WHILE num > 0
digit = num % 10
rev = rev * 10 + digit
num = num / 10 (integer division)
Step 5: OUTPUT rev
Step 6: END
This algorithm extracts digits from right to left using the remainder and integer division, and rebuilds the number in reverse order.
Similar in structure to reversing a number, the sum of digits algorithm accumulates digit = num % 10 into a running sum and then discards the digit using num = num // 10, repeating until num becomes 0.
Two powerful problem-solving techniques are decomposition and generalisation.
Once the algorithm and flowchart are ready, the algorithm is translated into a programming language. For example, the algorithm to reverse a number becomes the following Python program:
num = int(input("Enter a number: "))
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num = num // 10
print("Reversed number:", rev)
The program is then tested with several inputs, including edge cases such as 0, a single digit, and numbers ending in zeros, to verify correctness. This testing phase may reveal bugs that require the algorithm or the code to be refined.
| Step | Description |
|---|---|
| Analyse | Identify inputs, process and expected outputs |
| Develop algorithm | Design a finite, unambiguous step-by-step procedure |
| Code | Translate the algorithm into a programming language |
| Test and debug | Run with sample data and remove errors |
| Document | Add comments and keep the solution maintainable |
| Symbol | Shape | Purpose |
|---|---|---|
| Terminator | Oval | Start or end of program |
| Process | Rectangle | Computation or processing step |
| Input/Output | Parallelogram | Reading or printing data |
| Decision | Diamond | Branching based on a Yes/No condition |
| Flow line | Arrow | Direction of control flow |
Problem solving is the true essence of computer science. A clear process, analyse the problem, develop an algorithm, code it, and test it, converts a vague requirement into a working program. Algorithms must be finite, definite, effective and complete, and they can be expressed as pseudocode or flowcharts for clarity. Techniques such as decomposition and generalisation turn daunting problems into manageable parts and reusable solutions. With this systematic mindset established, the next chapter begins the actual journey of programming by getting started with the Python language, where all these ideas will be put into practice.