Unit 1: Problem Solving
Lecture Notes (Based on Pearson Edexcel IGCSE Computer Science Student Book Sample)
1. Introduction to Problem Solving
Problem solving in Computer Science involves understanding a problem, identifying inputs and
outputs, and designing a method (algorithm) to transform the inputs into the desired outputs.
Example:
Task: Making a cup of tea.
Inputs: water, tea, milk, sugar.
Process: boil water, add tea leaves, mix with milk and sugar.
Output: a cup of tea ready to drink.
2. Algorithms
An algorithm is a step-by-step procedure for solving a problem. It must be precise, finite, and
unambiguous. Algorithms can be represented using pseudocode or flowcharts.
Worked Example:
Algorithm to assign grades based on exam score:
1. RECEIVE examScore FROM keyboard
2. IF examScore >= 80 THEN SEND 'A'
3. ELSE IF examScore >= 70 THEN SEND 'B'
4. ELSE IF examScore >= 60 THEN SEND 'C'
5. ELSE IF examScore > 0 THEN SEND 'D'
6. ELSE SEND 'FAIL'
3. Algorithmic Constructs
Algorithms are built using three basic constructs:
- Sequence: Instructions are executed one after another in order.
- Selection: Decisions are made using conditions (e.g., IF statements).
- Iteration: Instructions are repeated until a condition is met (loops).
Example:
Algorithm to calculate the sum of the first 10 numbers:
total = 0
FOR i = 1 TO 10
total = total + i
NEXT i
SEND total
4. Sorting and Searching Algorithms
Sorting arranges data into order, while searching finds specific values in a dataset. Efficient
algorithms are needed to handle large datasets effectively.
Bubble Sort Example:
1. Compare two adjacent items.
2. Swap them if they are in the wrong order.
3. Continue until the end of the list.
4. Repeat until no swaps are needed.
Worked Example: Sort [4, 2, 6, 1, 3] into ascending order step by step.
Linear Search Example:
To find a target in a list, start at the first item and check each one until the target is found or the list
ends.
5. Decomposition and Abstraction
Decomposition means breaking down a complex problem into smaller, manageable sub-problems.
Abstraction means focusing on the essential details of a problem and ignoring unnecessary
complexity.
Example:
A school management system can be decomposed into modules like student registration,
attendance tracking, and grade reporting. Abstraction ensures that users see only the important
details (e.g., a simple interface) while technical details such as database queries remain hidden.