Algorithmic Problem-Solving Guides: Designing Algorithms From Problem Statements (Copy)
Designing Algorithms From Problem Statements
What “Designing Algorithms From Problem Statements” Means
- Converting a written problem into:
- A clear logical plan
- Step-by-step pseudocode
- Focus is on:
- Understanding what is given
- Understanding what is required
- Designing logic that is:
- Correct
- Efficient
- Examiner-friendly
- This skill is tested in:
- Structured questions
- Scenario-based problems
- Full algorithm design questions
Core Examiner Expectation (Very Important)
- Examiners do not reward clever tricks
- They reward:
- Clear logic
- Correct sequencing
- Appropriate use of:
- Selection
- Iteration
- Arrays
- Variables
The 6-Step Algorithm Design Framework (Use This Every Time)
Step 1: Read The Problem Slowly (Not Once — Twice)
- First read:
- Understand the context
- Second read:
- Identify inputs, outputs, conditions
Step 2: Identify Inputs, Outputs And Processing
| Element | What To Look For |
|---|---|
| Inputs | Values given by user / system |
| Outputs | What must be displayed / returned |
| Processing | Calculations, decisions, repetition |
Example Breakdown
Problem Statement (Simplified)
“Input 10 numbers and count how many are positive.”
| Category | Identified |
|---|---|
| Input | 10 numbers |
| Output | Count of positive numbers |
| Processing | Comparison + counting |
Step 3: Choose The Correct Data Structures
Ask These Questions
- Single value or multiple values?
- Fixed quantity or variable size?
- Order matters or not?
Common Choices
| Requirement | Best Choice |
|---|---|
| Single value | Variable |
| Multiple values | Array |
| Repeated input | Loop |
| Table data | 2D array |
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Step 4: Choose Correct Control Structures
Selection (IF / ELSE)
Use when:
- A decision must be made
- Different actions based on conditions
Iteration (Loops)
Use when:
- Repetition is required
- Number of repetitions known → FOR
- Number unknown → WHILE / REPEAT UNTIL
Control Structure Mapping
| Problem Clue | Use |
|---|---|
| “For each” | FOR loop |
| “Until valid” | REPEAT UNTIL |
| “While condition holds” | WHILE |
| “If condition met” | IF |
Step 5: Design The Algorithm In Logical Stages
Examiner-Preferred Structure
- Initialisation
- Input
- Processing
- Output
Example Algorithm Skeleton
<initialise variables>
<input data>
<process data>
<output result>
- This structure is extremely examiner-friendly
Step-By-Step Worked Example 1
Problem
“Input 5 numbers and display the largest.”
Step 1: Identify Elements
| Element | Detail |
|---|---|
| Input | 5 numbers |
| Output | Largest number |
| Processing | Comparison |
Step 2: Algorithm Design Logic
- Store numbers
- Track maximum
- Compare each new value
Step 3: Pseudocode
INPUT num
max ← num
FOR i ← 2 TO 5
INPUT num
IF num > max THEN
max ← num
ENDIF
NEXT i
OUTPUT max
- Correct initialisation
- Correct comparison logic
- No unnecessary array usage
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Step-By-Step Worked Example 2 (Arrays + Loops)
Problem
“Input marks of 10 students and count how many scored at least 50.”
Step 1: Identify Elements
| Element | Detail |
|---|---|
| Input | 10 marks |
| Output | Count |
| Processing | Comparison + counting |
Step 2: Choose Structures
- Array for marks
- FOR loop for traversal
- IF for decision
Step 3: Pseudocode
count ← 0
FOR i ← 1 TO 10
INPUT mark
IF mark >= 50 THEN
count ← count + 1
ENDIF
NEXT i
OUTPUT count
- Clean
- Minimal
- Examiner-safe
Step-By-Step Worked Example 3 (Validation)
Problem
“Keep asking the user for a number between 1 and 100 until valid.”
Design Choice
- REPEAT UNTIL
- Validation condition
Pseudocode
REPEAT
INPUT num
UNTIL num >= 1 AND num <= 100
- Loop executes at least once
- Condition correctly written
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Handling Multi-Part Problem Statements
Examiner Trick
- Problems often include:
- Multiple tasks in one paragraph
Example
“Input 20 numbers, store them, then display the average of positive values only.”
Break Into Sub-Tasks
- Input numbers
- Store values
- Filter positives
- Calculate sum
- Calculate average
- Output result
Pseudocode
sum ← 0
count ← 0
FOR i ← 1 TO 20
INPUT num
IF num > 0 THEN
sum ← sum + num
count ← count + 1
ENDIF
NEXT i
IF count > 0 THEN
average ← sum / count
OUTPUT average
ENDIF
Common Algorithm Design Mistakes
Mistake 1: Writing Code Before Understanding Problem
- Leads to:
- Missing conditions
- Wrong output
Mistake 2: Overusing Arrays
- Arrays used when:
- Not needed
- No later access required
Mistake 3: Wrong Loop Choice
- Using FOR when repetitions unknown
- Using WHILE when FOR is simpler
Mistake 4: Missing Initialisation
total ← total + num
totalnot initialised
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Algorithm Design Checklist (Before Writing Final Answer)
- Have all inputs been identified?
- Are outputs clearly stated?
- Is every variable initialised?
- Are conditions logically correct?
- Will loops always terminate?
- Is the solution simple and readable?
Examiner Language You Should Reflect
- “Initialise”
- “Input”
- “Process”
- “Output”
- Clear variable names
- Clear structure
Exam-Ready Algorithm Design Template (Use This)
<initialise variables>
FOR / WHILE / REPEAT
<input>
<processing>
END LOOP
<output>
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
One-Line Rules To Memorise
- Understand before coding
- Break problems into steps
- Choose simplest structure
- Initialise everything
- Clarity beats cleverness
