ALGORITHM DESIGN AND IGCSE II
PROBLEM SOLVING
PROGRAM DEVELOPMENT LIFE CYCLE
(PDLC)
The PDLC has five main stages
• Analysis
• Design
• Coding
• Testing
• Maintenance
ANALYSIS
• Understand the problem (Requirements Specification).
• Use abstraction to focus on important details only.
• Use decomposition to break the problem into smaller,
manageable parts.
• Example: Getting dressed → choose clothes → remove old
ones → wear new ones.
DESIGN
• Plan how the program will solve the problem.
• Identify all tasks and how they connect.
• Use tools like:
• Structure charts
• Flowcharts
• Pseudocode
CODING & ITERATIVE TESTING
• Write the program in a programming
language.
• Test each part (module) as you build it.
• Fix and retest repeatedly until it works
correctly (iterative testing).
FINAL TESTING
• Run the whole program with various test
data.
• Ensure all parts work together as planned.
• Confirm the program meets the original
requirements.
STRUCTURE DIAGRAM
• Structure diagrams can be used to show
top-down design in a diagrammatic form.
• Showing how a computer system solution can
be divided into sub-systems with each level
giving a more detailed breakdown
STRUCTURE DIAGRAM
System
Sub System 1 Sub System 2 Sub System 3
Sub System 4 Sub System 5
ALARM APP FOR A SMART PHONE
Alarm App
Set Alarm Check Time Sound Alarm
Play Sound
Set Time Turn alarm ON/OFF Check Reset/Clear
For two
off/snooze alarm
minutes
FLOWCHART
• A flowchart is a diagram that represents
the step-by-step control flow of an algorithm
• Using symbols (start/stop, process,
decision, input/output) linked by arrows to
show the order in which the steps are
executed.
FLOWCHART
START
Terminator
flow chart
symbol
STOP
Process details
PROCESS include this flow
chart symbol
Process flow chat A 0
symbols are used to B 0
show action . When
value are assigned
to the variable.
somewhere
Predefine
else SHORT LIST
INPUT/OUTPUT
INPUT X
OUTPUT
“ERROR”
DECISON
Decision symbol are used
to decide which action is
be taken next
YES
A>B BX
NO
FORMATTING CONVENTIONS
• Use non-proportional font .
• Keywords (e.g., INPUT, IF, WHILE) are
written in capital letters.
• Variables and subroutine names begin
with a capital letter.
• Use indentation (2 spaces) for blocks
inside conditions or loops.
ASSIGNMENT STATEMENTS
Operator Action
+ Add
- Subtract
* Multiply
/ Divide
^ Raise to the power
( ) Group
ASSIGNMENT STATEMENTS
• Cost 10
• Price Cost * 2
• Tax Price * 0.12
• SellingPrice Price + Tax
• Gender "M"
• Chosen False
CONDITIONAL STATEMENTS IN
PSEUDOCODE
• Conditional statements allow
an algorithm to make decisions
based on variable values.
IF ... THEN ... ELSE ... ENDIF
Used when a condition can be true or false.
• IF Age < 18
• THEN
• OUTPUT "Child"
• ELSE
• OUTPUT "Adult"
• ENDIF
1. Write a pseudocode to input a number and check whether it is even or
odd.
2. Write a pseudocode that takes a number as input and displays whether
it is positive, negative, or zero.
3. Write a pseudocode to input two numbers and display the greater one.
4. Write a pseudocode to input a student’s marks and display the
grade according to the following:
80 and above → A
70–79 → B
60–69 → C
Below 60 → Fail
Write a pseudocode to input a number and check
whether it is even or odd.
INPUT number
IF number MOD 2 = 0 THEN
OUTPUT "The number is even"
ELSE
OUTPUT "The number is odd"
ENDIF
Write a pseudocode that takes a number as input and
displays whether it is positive, negative, or zero.
INPUT number
IF number > 0 THEN
OUTPUT "Positive number"
ELSE IF number < 0 THEN
OUTPUT "Negative number"
ELSE
OUTPUT "Zero"
ENDIF
Write a pseudocode to input two numbers and display the
greater one.
INPUT num1, num2
IF num1 > num2 THEN
OUTPUT "First number is greater"
ELSE IF num2 > num1 THEN
OUTPUT "Second number is greater"
ELSE
OUTPUT "Both numbers are equal"
ENDIF
1. Write a pseudocode to input a student’s marks and display the grade
according to the following:
80 and above → A
70–79 → B
60–69 → C
Below 60 → Fail
INPUT marks
IF marks >= 80 THEN
OUTPUT "Grade A"
ELSE IF marks >= 70 THEN
OUTPUT "Grade B"
ELSE IF marks >= 60 THEN
OUTPUT "Grade C"
ELSE
OUTPUT "Fail"
ENDIF
TYPES OF CONDITIONS
Boolean Variable
A Boolean variable holds either TRUE or FALSE.
• IF Found
• THEN
• OUTPUT "Your search was successful"
• ELSE
• OUTPUT "Your search was unsuccessful"
• ENDIF
COMPARISON OPERATORS
• > (greater than)
• < (less than)
• = (equal to)
• <> (not equal to)
• >= (greater than or equal to)
• <= (less than or equal to)
COMBINED CONDITIONS WITH LOGIC
OPERATORS
AND
both conditions must be true
OR
at least one condition must be true
Conditions in brackets () help control the logic
TYPES OF CONDITIONS
Combined Conditions
• IF ((Height > 1) OR (Weight > 20)) AND (Age <
70) AND (Age > 5)
• THEN
• OUTPUT "You can ride"
• ELSE
• OUTPUT "Too small, too young or too old"
• ENDIF
CASE ... OF ... OTHERWISE ... ENDCASE
Used when choosing between several possible values
• CASE OF Grade
• "A" : OUTPUT "Excellent"
• "B" : OUTPUT "Good"
• "C" : OUTPUT "Average"
• OTHERWISE OUTPUT "Improvement is needed"
• ENDCASE
ACTIVITY
1. Check if a percentage mark is valid (between 0
and 20),
2. Pass mark is now 10 or higher,
3. Use a nested IF statement.
PSEUDOCODE
1. OUTPUT "Please enter a mark"
2. INPUT PercentageMark
3. IF PercentageMark < 0 OR PercentageMark > 20
4. THEN
5. OUTPUT "Invalid Mark"
6. ELSE
7. IF PercentageMark >= 10
8. THEN
9. OUTPUT "Pass"
10. ELSE
11. OUTPUT "Fail"
12. ENDIF
13. ENDIF
PSEUDOCODE
1. The CASE structure chooses a path based on the value of a variable.
2. CASE OF Choice
3. 1 : Answer Num1 + Num2
4. 2 : Answer Num1 - Num2
5. 3 : Answer Num1 * Num2
6. 4 : Answer Num1 / Num2
7. OTHERWISE OUTPUT "Please enter a valid choice"
8. ENDCASE