Chapter 4 – Introduction to Problem Solving
1. Problem Solving
● Problem solving is the process of identifying a problem, analyzing it, and developing
a step-by-step solution.
● In Computer Science, problem solving means designing algorithms that can be
implemented using a programming language.
2. Steps of Problem Solving
The systematic process of solving a problem involves:
● Understanding the Problem
● Clearly define what is required.
● Identify inputs, expected outputs, and constraints.
● Analyzing the Problem
● Break the problem into smaller parts.
● Check feasibility (can it be solved with given resources?).
● Developing a Solution (Algorithm/Flowchart)
● Plan a step-by-step procedure.
Represent the solution using:
● Algorithm (text-based steps).
● Flowchart (graphical representation).
● Coding
● Translate the algorithm into a programming language (like Python).
● Testing and Debugging
● Run the program with sample data.
● Identify and correct errors (bugs).
● Documentation and Maintenance
● Maintain proper explanation, comments, and user manuals.
● Update or modify the program as per new requirements.
3. Problem-Solving Tools
(a) Algorithm
An algorithm is a finite sequence of well-defined instructions to solve a problem.
Characteristics:
● Finiteness – Must terminate after a finite number of steps.
● Definiteness – Each step must be clear and unambiguous.
● Input – Zero or more inputs are taken.
● Output – At least one output is produced.
● Effectiveness – Steps must be basic enough to be carried out.
●
Example – Algorithm to find sum of two numbers:
Start
Input two numbers A, B
Compute SUM = A + B
Display SUM
Stop
(b) Flowchart
A graphical representation of the steps of an algorithm.
Uses standard symbols:
Symbol Meaning
⃝ / ⬭ (Oval) Start/Stop
⬜ (Parallelogram) Input/Output
▭ (Rectangle) Processing (Calculation/Assignment)
⬠ (Diamond) Decision / Condition
→ (Arrow) Flow of control
● Advantages: Easy to understand, debug, and communicate logic.
● Disadvantages: Time-consuming, difficult for large problems.
4. Programming Approach
(a) Top-Down Approach
● Breaks a large problem into smaller sub-problems (modules).
● Each sub-problem is solved independently.
● Example: Designing a calculator program → break into modules (input, add, subtract,
display).
● Advantages: Easier debugging, better management, reusability.
(b) Bottom-Up Approach
● Start solving small components first, then integrate them into a complete system.
● Example: Write functions for addition, subtraction, multiplication, division, then
combine.
5. Types of Errors in Problem Solving
● Syntax Error – Wrong grammar of programming language (e.g., missing colon in
Python).
● Logical Error – Program runs but gives wrong output due to wrong logic.
● Runtime Error – Errors during execution (e.g., division by zero).
6. Problem Solving Example
Problem: Find the largest of three numbers.
● Algorithm:
Start
Input three numbers A, B, C
If A > B and A > C, then Largest = A
Else if B > C, then Largest = B
Else Largest = C
Print Largest
Stop
● Flowchart:
Start → Input A, B, C → Compare numbers using decision diamonds → Output Largest →
Stop
7. Importance of Problem Solving in Computer Science
● Helps in systematic thinking.
● Reduces chances of errors.
● Makes debugging and program modification easier.
● Essential skill for programming and real-life applications.