ЁЯФм
ЁЯзм
ЁЯФн
ЁЯкР
ЁЯзк
тЖР Back to Dashboard
Font Size:

1. Introduction

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.

2. Steps for Problem Solving

Solving a problem with a computer typically follows these steps:

  1. Analysing the problem: Understand what the problem is asking. Identify the inputs, the expected outputs, and the constraints. Ask questions like: What data is available? What processing is required? What is the form of the result?
  2. Developing an algorithm: Design a step-by-step procedure that transforms the given inputs into the required outputs. The algorithm must be finite, unambiguous and effective.
  3. Coding: Translate the algorithm into a programming language such as Python. The program is the machine-readable version of the algorithm.
  4. Testing and debugging: Run the program with sample data, compare the output with the expected results, and remove errors (bugs) until the program behaves correctly.
  5. Documentation and maintenance: Write comments and documentation to make the program understandable, and update it as requirements change.

3. Analysing the Problem

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.

3.1 Identifying Inputs and Outputs

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.

4. Algorithm and Its Characteristics

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:

5. Pseudocode

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.

6. Flowcharts

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.

6.1 Example: Flowchart for Finding Factorial

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.

7. Algorithms for Common Problems

The following are classic examples that every class 11 student should master.

7.1 Algorithm to Check if a Number is Prime

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.

7.2 Algorithm to Reverse a Number

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.

7.3 Algorithm to Find the Sum of Digits

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.

8. Decomposition and Generalisation

Two powerful problem-solving techniques are decomposition and generalisation.

9. From Algorithm to Program

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.

Quick Revision Tables

Table 1: Steps of Problem Solving

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

Table 2: Flowchart Symbols

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

Mind Map

flowchart TD A[Problem Solving] --> B[Steps] B --> B1[Analysis] B --> B2[Algorithm] B --> B3[Coding] B --> B4[Testing] B --> B5[Documentation] A --> C[Algorithm] C --> C1[Finite] C --> C2[Unambiguous] C --> C3[Effective] C --> C4[Has Input/Output] A --> D[Representation Tools] D --> D1[Pseudocode] D --> D2[Flowchart] A --> E[Techniques] E --> E1[Decomposition] E --> E2[Generalisation] E --> E3[IPO Analysis] A --> F[Examples] F --> F1[Prime Check] F --> F2[Reverse Number] F --> F3[Sum of Digits]

Important Diagrams (SVG)

Diagram 1: Problem Solving Process Flow

Steps of Problem Solving START (Analyse) Develop Algorithm Write Code Test and Debug Correct Result Bug found? Go back Golden Rule: Analyse the problem fully before writing a single line of code; coding is the last step.

Diagram 2: Flowchart for Reversing a Number

Flowchart: Reverse a Number START INPUT num rev = 0 digit = num % 10 rev = rev*10 + digit num = num // 10 num > 0? No -> repeat Yes -> PRINT rev Golden Rule: digit = num % 10 extracts the last digit; num = num // 10 removes it. Always verify edge cases.

Common Mistakes

  1. Skipping problem analysis: Writing code immediately without identifying inputs, outputs and edge cases produces incorrect programs.
  2. Writing non-terminating algorithms: An algorithm without a proper loop-exit condition keeps running forever and is not a valid algorithm.
  3. Using ambiguous instructions: Steps like "choose a big number" are indefinite; each step must have exactly one meaning.
  4. Confusing flowchart symbols: Using a rectangle for a decision or an oval for a process leads to a wrong flowchart. Diamonds are for decisions only.
  5. Ignoring edge cases: For the reverse-number algorithm, forgetting that 0 or single-digit numbers need handling produces wrong answers.
  6. Confusing modulo and floor division: num % 10 gives the last digit, while num // 10 removes it; swapping these destroys the logic.
  7. Thinking pseudocode is runnable code: Pseudocode is not executable; it is only a human-readable plan that must later be translated into Python.

Exam Tips

  1. Always write the characteristics of an algorithm (finiteness, definiteness, input, output, effectiveness) when asked to define it; mention all five.
  2. Practise drawing labelled flowcharts using the five standard symbols, because diagram questions carry dedicated marks.
  3. For "write an algorithm" questions, present steps in numbered form beginning with START and ending with END.
  4. Include edge-case handling in your algorithm, for example handling num = 0 when reversing a number.
  5. Learn the classic algorithms (prime check, reverse number, sum of digits, largest of three) thoroughly; variations of these appear frequently.
  6. Use dry runs: trace your algorithm with a small example (like 347) by hand before writing code, to catch logic errors.
  7. Define decomposition and generalisation clearly with one example each; they are common short-answer questions.

Conclusion

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.