Write and amend algorithms using pseudocode, program code and flowcharts

Algorithm Design and Problem‑Solving

What is an Algorithm? 🤔

An algorithm is a clear, step‑by‑step set of instructions that solves a problem or performs a task. Think of it like a recipe for baking a cake: you need a list of ingredients, the order in which you add them, and how long to bake. Just as a recipe guarantees a tasty cake, a well‑written algorithm guarantees a correct result.

Steps in Designing an Algorithm 🚀

  1. Understand the problem – Read the question carefully and identify the input, output, and constraints.
  2. Plan a solution – Sketch a rough idea or use a flowchart to visualise the process.
  3. Write pseudocode – Draft a human‑readable version of the algorithm.
  4. Translate to code – Convert the pseudocode into a programming language.
  5. Test and debug – Run the algorithm with sample data, check for errors, and refine.

Pseudocode 📜

Pseudocode is a mix of plain English and programming concepts. It helps you focus on logic without worrying about syntax.

// Calculate factorial of n
INPUT n
IF n == 0 THEN
    result ← 1
ELSE
    result ← 1
    FOR i FROM 1 TO n DO
        result ← result × i
    END FOR
END IF
OUTPUT result
  

Mathematical notation: $n! = n \times (n-1) \times \dots \times 1$.

Program Code (Python Example) 🐍

def factorial(n):
    """Return n! for a non‑negative integer n."""
    if n == 0:
        return 1
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

# Example usage
print(factorial(5))  # Output: 120
  

Flowcharts 🔄

Flowcharts use shapes to represent different actions:

  • Oval – Start or End
  • Rectangle – Process or instruction
  • Diamond – Decision (yes/no)
  • Parallelogram – Input/Output

Example (factorial):

Start → Input n → If n = 0? → Yes → Output 1 → End

Otherwise → Set result = 1 → For i = 1 to n → result = result × i → End For → Output result → End

Exam Tips for IGCSE 0478 📝

  • Read the question exactly – Identify required input, output, and any constraints.
  • Use clear headings in your pseudocode (e.g., INPUT, PROCESS, OUTPUT).
  • Show flowchart symbols correctly; teachers look for the right shapes.
  • When writing code, include comments to explain non‑obvious parts.
  • Test your algorithm with edge cases (e.g., n = 0, n = 1).
  • Keep your pseudocode concise – avoid unnecessary words.

Comparison Table: Pseudocode vs. Python Code

Step Pseudocode Python Code
Input INPUT n n = int(input("Enter n: "))
Initialisation result ← 1 result = 1
Loop FOR i FROM 1 TO n DO for i in range(1, n + 1):
Multiply result ← result × i result *= i
Output OUTPUT result print(result)

Revision

Log in to practice.

0 views 0 suggestions