TOPIC 8 PROBLEM SOLVING
Problem solving is an important skill in Computer Science that involves identifying a problem, analyzing it, and developing a logical solution. Computers solve problems by following instructions provided in a systematic manner.
I. CONCEPT OF PROBLEM SOLVING
Problem solving is the process of finding a solution to a given problem by following logical and systematic steps. In computer science, problems are solved using algorithms and computer programs.
Example: Using a computer to calculate student results instead of doing it manually.
Practical Activity
Identify one school problem that can be solved using a computer.
Scenario Activity
Explain why computers cannot solve problems without instructions.
II. IDENTIFICATION OF A PROBLEM
Problem identification involves clearly recognizing and defining the problem to be solved. A problem must be well understood before attempting to find a solution. Example: Identifying that manual calculation of marks causes delays and errors.
Practical Activity
List three problems in daily life that can be suitable for computer solutions.
Scenario Activity
Explain the effects of poorly defined problems in computer problem solving.
III. ANALYSIS OF A PROBLEM
Problem analysis involves breaking a problem into smaller manageable parts. This includes identifying inputs, processes, and outputs.
Example:
Input: Student marks
Process: Add marks and divide by number of subjects
Output: Average marks
Practical Activity
Analyze the steps required to calculate total marks for a class.
Scenario Activity
Why is problem analysis important before designing a solution?
IV. DESIGNING A SOLUTION
Designing a solution involves planning how the problem will be solved before writing a computer program. This is done using algorithms, pseudocode, and flowcharts.
A. ALGORITHM
An algorithm is a finite, step-by-step set of logical instructions used to solve a problem. It must be clear, precise, and arranged in logical order.
Characteristics of a good algorithm
i. It must have a clear start and end.
ii. Each step must be clear and unambiguous.
iii. It must produce a result.
iv. It must be finite.
v. Steps must follow logical order.
Example 1: Algorithm to add two numbers
i. Start
ii. Input first number A
iii. Input second number B
iv. Add A and B
v. Display the sum
vi. End
Example 2: Algorithm to calculate student average
i. Start
ii. Input marks for all subjects
iii. Calculate total marks
iv. Divide total by number of subjects
v. Display average
vi. End
Practical Activity
Write an algorithm to calculate the area of a triangle.
Scenario Activity
Explain what may happen if algorithm steps are not arranged correctly.
B. CONSTRUCTION OF AN ALGORITHM
Algorithm construction refers to the process of developing an algorithm by identifying inputs, processes, and outputs.
i. Identify the problem to be solved.
ii. Determine the required inputs.
iii. Identify processing steps.
iv. Determine the expected output.
v. Arrange steps logically.
Example:
Problem: Calculate total marks
Input: Subject marks
Process: Add all marks
Output: Total marks
Practical Activity
Construct an algorithm to determine whether a number is even or odd.
C. REPRESENTATION OF ALGORITHMS USING PSEUDOCODE
Pseudocode is a structured English description of an algorithm. It is not written in a programming language.
Example 1: Pseudocode to add two numbers
START
INPUT A
INPUT B
SUM = A + B
DISPLAY SUM
END
Example 2: Pseudocode to calculate student average
START
INPUT total Marks
INPUT number Of Subjects
average = total Marks / number Of Subjects
DISPLAY average
END
Practical Activity
Write pseudocode to calculate the perimeter of a rectangle.
D. CONTROL STRUCTURES IN ALGORITHMS
Control structures determine the order in which instructions are executed.
I. SEQUENCE CONTROL STRUCTURE
Sequence executes instructions in order.
Example Algorithm
START
INPUT length
INPUT width
area = length × width
DISPLAY area
END
Flowchart Diagram (Sequence)
┌─────────┐
│ START │
└────┬────┘
│
┌────▼────┐
│ INPUT │
│ length │
└────┬────┘
│
┌────▼────┐
│ INPUT │
│ width │
└────┬────┘
│
┌────▼────┐
│ PROCESS │
│ area = │
│ length× │
│ width │
└────┬────┘
│
┌────▼────┐
│ DISPLAY │
│ area │
└────┬────┘
│
┌────▼────┐
│ END │
└─────────┘
Mr. Edward A.Y Bagamoyo 0764096482
41
II. SELECTION CONTROL STRUCTURE
Selection allows decision making based on conditions. Example Algorithm
START
INPUT marks
IF marks ≥ 50
DISPLAY PASS
ELSE
DISPLAY FAIL
END IF
END
Flowchart Diagram (Selection)
┌─────────┐
│ START │
└────┬────┘
│
┌────▼────┐
│ INPUT │
│ marks │
└────┬────┘
│
┌────▼────┐
│ DECISION│
│ marks ≥50? │
└────┬────┘
YES │ NO
┌───▼───┐ ┌───▼───┐
│ DISPLAY│ │ DISPLAY│
│ PASS │ │ FAIL │
└───┬───┘ └───┬───┘
│ │
└─────────┘
│
┌──▼──┐
│ END │
└─────┘
III. ITERATION CONTROL STRUCTURE
Iteration allows repetition of steps until a condition is met.
Example Algorithm
START
SET total = 0
FOR i = 1 TO 5
INPUT mark
total = total + mark
END FOR
DISPLAY total
END
Flowchart Diagram (Iteration)
┌─────────┐
│ START │
└────┬────┘
│
┌───────▼────────┐
│ total = 0, i=1 │
└───────┬────────┘
│
┌────▼────┐
│ INPUT │
│ mark │
└────┬────┘
│
┌────▼────┐
│ PROCESS │
│ total= │
│ total+mark│
└────┬────┘
│
┌────▼────┐
│ i = i+1 │
└────┬────┘
│
┌────▼────┐
Practical Activity
│ DECISION│
│ i ≤ 5 ? │
└───┬─────┘ YES │ NO
┌───▼───┐ │ REPEAT │
└───┬───┘ │
┌▼┐
│DISPLAY│
│ total │
└──┬───┘
│
┌──▼──┐
│ END │
└─────┘
Write an algorithm using iteration to display numbers from 1 to 10.
E. FLOWCHART SYMBOLS USED IN PROBLEM SOLVING
i. Oval represents Start or End
ii. Parallelogram represents Input or Output
iii. Rectangle represents Processing
iv. Diamond represents Decision
v. Arrow represents Flow of control
Scenario Activity
Explain why flowcharts are important in solving complex problems.
V. IMPLEMENTATION OF THE SOLUTION
Implementation involves converting the designed solution into a computer program. Example: Writing a program in Scratch or Python to calculate grades.
Practical Activity
Write simple instructions to display your name on the screen.
Scenario Activity
What problems may occur if a solution is poorly implemented?
VI. TESTING AND DEBUGGING
Testing checks whether a program works correctly, while debugging removes errors.
i. Syntax errors occur due to incorrect commands.
ii. Logic errors occur when output is incorrect.
iii. Runtime errors occur during program execution.
Practical Activity
Test a simple program and identify errors.
Scenario Activity
Explain why testing is important before using a program.
vii. DOCUMENTATION AND MAINTENANCE
Documentation records how a solution works, while maintenance involves updating and improving it.
- Documentation helps users understand the solution.
- Maintenance ensures the solution continues to meet needs.
Example: Updating a school system to include new subjects.
Practical Activity
Write short documentation for a simple algorithm.
Scenario Activity
Why is maintenance important after problem solving?



































Leave a Reply