General Algorithms (Edexcel A-Level Further Mathematics): Revision Notes
10.1.1 General Algorithms
What Are Algorithms?
An algorithm is a step-by-step set of instructions designed to solve a problem or perform a task. Algorithms can be implemented using flowcharts, pseudocode, or computer programmes and are fundamental to solving mathematical, computational, and network problems.
Components of an Algorithm
- Input: Data provided to the algorithm to process.
- Process: The steps or rules that transform the input.
- Output: The result or solution derived from the process.
Representing Algorithms
Flowcharts
Flowcharts visually represent the steps in an algorithm. Common flowchart symbols include:
- Oval (Start/End): Indicates the beginning or end of a process.
- Rectangle (Process): Represents a task or operation.
- Diamond (Decision): Represents a decision point with multiple outcomes.
- Arrows: Indicate the flow of steps.
Pseudocode
Pseudocode describes algorithms in a structured, human-readable format that mimics programming logic. It is not tied to any specific programming language.
Efficiency of Algorithms
The order of an algorithm measures its efficiency, typically in terms of time or computational resources required as the size of the input grows.
Big-O Notation
Big-O notation describes the upper bound of an algorithm's complexity:
- : Constant time (independent of input size).
- : Linear time (directly proportional to input size).
- : Quadratic time (e.g., nested loops).
- : Logarithmic time (e.g., binary search).
Worked Examples
Example 1: Flowchart Algorithm
Design a flowchart to determine whether a number is even or odd.
Steps:
- Start.
- Input
- Check
- If true, output "Even."
- If false, output "Odd."
- End.
Pseudocode**:**
BEGIN
Input n
IF n MOD 2 = 0 THEN
Output "Even"
ELSE
Output "Odd"
ENDIF
END
Example 2: Determine the Order of an Algorithm
Problem:
Given an algorithm that multiplies two matrices using three nested loops:
Solution:
- Each loop runs times.
- The total number of operations is proportional to
- Order: The algorithm is
Example 3: Shortest Path Algorithm
Find the shortest path between two nodes in a graph using Dijkstra's algorithm.
Order of the Algorithm:
Using a priority queue for efficient selection of the smallest distance:
- Priority queue operations take
- Processing all edges takes , where is the number of edges.
- Thus, the algorithm's order is
Note Summary
Common Mistakes
- Misinterpreting flowcharts: Be careful with decision points; clearly follow branches.
- Forgetting base cases: Recursive algorithms often fail without proper termination conditions.
- Overlooking efficiency: Always analyse the time complexity of nested loops or iterative steps.
- Incorrect initialisation: Ensure variables (e.g., distances in shortest path problems) are initialised correctly.
- Confusing pseudocode with implementation: Pseudocode is for planning, not direct coding.
Key Formulas
- Big-O Notation:
- : Constant time.
- : Linear time.
- : Quadratic time.
- : Logarithmic time.
-
Matrix Multiplication Complexity: for standard nested-loop algorithms.
-
Graph Search Algorithms:
- Dijkstra's Algorithm:
- Floyd-Warshall Algorithm: