Problem Solving Process
Six Steps of Computer-Based Problem Solving
1. Problem Definition
First, we must clearly understand what problem needs to be solved.
We identify:
- What is the input?
- What should be the output?
- What are the constraints?
- What exactly is the objective?
Example
Problem: Find the largest number in a list.
Input → [12, 45, 7, 32, 18] Output → 45
Before writing any code, we must clearly understand what is required.
Key question: What exactly do I need to solve?
2. Algorithm Design
Once the problem is understood, we develop a step-by-step procedure to solve it.
For finding the largest number:
1. Assume the first number is the largest. 2. Compare it with the next number. 3. If the next number is larger, make it the largest. 4. Continue until all numbers are checked. 5. Display the largest number.
This is the algorithm.
Key question: How can I solve the problem step by step?
3. Implementation
Now we convert the algorithm into a program using a programming language such as Python, C, Java, etc.
For example, the algorithm can be implemented in Python:
numbers = [12, 45, 7, 32, 18] largest = numbers[0] for number in numbers: if number > largest: largest = number print(largest)
The computer cannot directly execute our informal algorithm. It needs instructions written in a programming language.
Key question: How can I express my algorithm in a programming language?
4. Execution
The computer now runs the program.
For the given input:
[12, 45, 7, 32, 18]
the program compares the numbers and produces:
Largest = 45
During execution, the computer:
Input ↓ Program instructions ↓ Processing ↓ Output
Key question: What happens when the computer runs my program?
5. Testing and Debugging
A program that runs without a syntax error is not necessarily correct.
We must test it with different inputs.
For example:
Test 1: [12, 45, 7, 32] → 45 ✓ Test 2: [5, 2, 9, 1] → 9 ✓ Test 3: [-5, -2, -10] → -2 ✓ Test 4: [7] → 7 ✓
If the program produces an incorrect result, we identify and fix the error.
Common types of errors include:
- Syntax error – incorrect programming language syntax
- Logical error – program runs but produces the wrong answer
- Runtime error – error occurs while the program is running
Key question: Does my program produce the correct result for different inputs?
6. Optimization, Documentation and Maintenance
Once the program is working correctly, we can improve it.
Optimization
We ask:
Can the program be made faster or use less memory?
For example, if a program takes too long for a very large input, we may need to design a more efficient algorithm.
Documentation
We explain:
- What the program does
- How the algorithm works
- Important design decisions
- How to use the program
Maintenance
After the program is deployed, we may need to:
- Fix newly discovered bugs
- Add new features
- Modify the program for new requirements
- Improve performance
Key question: Can I make the solution better and maintainable?
Complete Process at a Glance
PROBLEM ↓ 1. Define the Problem ↓ 2. Design the Algorithm ↓ 3. Implement the Algorithm ↓ 4. Execute the Program ↓ 5. Test & Debug ↓ 6. Optimize, Document & Maintain ↓ SOLUTION
A Simple Example for Students
Suppose the problem is:
“Calculate the average marks of five students.”
| Step | What we do |
|---|---|
| 1. Problem Definition | Input = 5 marks; Output = average |
| 2. Algorithm Design | Add all marks and divide by 5 |
| 3. Implementation | Write the program in Python/C/Java |
| 4. Execution | Run the program with marks |
| 5. Testing & Debugging | Test with different marks and correct errors |
| 6. Optimization & Maintenance | Improve the program and modify it if requirements change |
Remember these six questions:
1. What is the problem? → Problem Definition
2. How will I solve it? → Algorithm Design
3. How do I write the solution? → Implementation
4. What happens when I run it? → Execution
5. Is the answer correct? → Testing & Debugging
6. Can I make it better? → Optimization & Maintenance
This gives students a clear connection between problem-solving, algorithmic thinking, and programming.
Comments
Post a Comment