🌟 Chapter: Introduction to Problem Solving
🔷 Introduction
Problem solving is one of the most important skills in computer science.
Whenever we need to write a program or build a system, we start with
understanding a problem and then work toward a solution.
In the context of programming:
A problem is a situation that requires a solution using logical steps.
A solution is the process that resolves the problem effectively.
Example:
If you want to calculate the average marks of 5 students, the problem is
“how to compute the average marks”, and the solution is the set of steps (an
algorithm) you use to calculate it.
🔷 Problem Solving Cycle
Problem-solving follows a logical cycle of steps to ensure we reach an
accurate and efficient solution. These steps are:
🔹 1. Understanding the Problem
You must first read and fully understand what is being asked. Identify:
What are the inputs?
What is the expected output?
Are there any conditions or constraints?
🔹 2. Planning the Solution
Once you understand the problem, decide how to solve it. You may:
Break it into smaller parts (decomposition),
Choose the correct formulas or logic,
Decide the flow of control (loops, decisions).
🔹 3. Executing the Plan
Now you actually solve the problem by:
Writing the algorithm,
Drawing flowcharts,
Writing pseudocode or code,
Running the solution.
🔹 4. Reviewing and Reflecting
After execution, you should:
Test the solution with different inputs,
Check for errors or logical mistakes,
Optimize the logic if necessary.
🔷 Problem Solving using Decomposition
Decomposition means breaking a big problem into smaller, more
manageable parts (sub-problems).
This makes it easier to understand and solve each part individually.
Example:
To create a program that calculates the grade of a student, you might
decompose the task into:
Getting input marks,
Calculating the total,
Calculating the percentage,
Determining the grade based on percentage.
🔷 Designing Algorithms
An algorithm is a set of clear and unambiguous instructions to solve a
specific problem.
A good algorithm should be:
Clear and precise,
Finite (it ends),
Efficient in time and space.
🔹 1 Flowcharts
A flowchart is a graphical representation of an algorithm using specific
symbols:
Oval: Start/End
Rectangle: Process/Action
Diamond: Decision (Yes/No)
Parallelogram: Input/Output
Benefits:
Easy to understand
Visualizes the flow of logic
Helps in debugging and planning
Example: A flowchart to check if a number is even or odd includes steps to
take input, check number % 2 == 0, and print "Even" or "Odd".
🔹 2 Pseudocode
Pseudocode is a way of writing the logic of a program using plain English,
without following the strict syntax of any programming language.
Purpose:
Helps in planning before writing real code.
Easy to modify or debug.
🔹 3 Verifying an Algorithm
Once the algorithm is written, we must verify it to ensure:
It works for all types of inputs,
It produces correct output,
It handles errors properly.
How to verify:
Test with sample inputs
Use dry runs (manually simulate the execution)
Handle boundary cases (like 0, negative numbers)
🔹 4 Comparing Algorithms
Often, more than one algorithm can solve the same problem. We compare
them based on:
Time Efficiency: How fast it runs (e.g., sorting 1000 numbers)
Space Efficiency: How much memory it uses
Readability and Maintainability: Is the logic simple and clean?
Example:
Sorting algorithms like Bubble Sort, Merge Sort, and Quick Sort all sort
elements, but their performance varies. Choosing the most efficient one is
important for large datasets.
✅ Key Takeaways
Problem-solving is a structured approach to finding solutions using
logic.
Flowcharts and pseudocode help in designing the solution clearly.
Verifying and comparing algorithms ensure correctness and efficiency.
Decomposition simplifies complex problems into easier sub-tasks.