Basic Algorithm Structure - StudyPulse
Boost Your VCE Scores Today with StudyPulse
8000+ Questions AI Tutor Help
Home Subjects Algorithmics (HESS) Algorithm structure

Basic Algorithm Structure

Algorithmics (HESS)
StudyPulse

Basic Algorithm Structure

Algorithmics (HESS)
01 May 2026

Basic Structure of Algorithms

What Is an Algorithm?

An algorithm is a finite, unambiguous sequence of instructions that solves a well-defined problem. Every algorithm must:
1. Terminate in a finite number of steps
2. Be unambiguous — each step has exactly one interpretation
3. Have a well-defined input and output
4. Be correct — produce the right output for every valid input

KEY TAKEAWAY: Algorithms are the computational heart of problem-solving. Every algorithm has structure: it begins, processes inputs through defined steps, and terminates with an output.

Components of an Algorithm

1. Name and Parameters

An algorithm begins with its name and the list of inputs (parameters).

ALGORITHM BinarySearch(A, target)
Input: Sorted array A, value target
Output: Index of target in A, or -1 if not found

2. Sequence (Steps)

Instructions are executed in order, one after another. This is the most fundamental control structure.

3. Variables and Assignment

Variables store and update data throughout the algorithm.

max ← A[0]
count ← 0

4. Conditionals

Branch the algorithm’s path based on a condition.

if x > max then
    max  x
end if

5. Iteration (Loops)

Repeat a block of instructions multiple times.

for i  0 to n-1 do
    ...
end for

while condition do
    ...
end while

6. Functions / Subroutines

Encapsulate reusable logic. Support modular design.

FUNCTION max(a, b)
    if a > b then return a
    else return b

7. Return

Output the result and terminate.

return result

Algorithm Template Structure

ALGORITHM Name(parameter1, parameter2, ...)
    // Pre-condition: what is true about inputs
    // Post-condition: what is true about the output

    Step 1: ...
    Step 2: ...
    ...
    return result

Correctness and Termination

An algorithm is correct if, for every valid input, it produces the correct output and terminates.

Proving termination: Show that each iteration makes measurable progress towards the termination condition (e.g., the search space shrinks, a counter decrements).

Proving correctness: Use loop invariants (for iterative algorithms) or induction (for recursive algorithms).

EXAM TIP: VCAA exams may ask you to trace through an algorithm manually with given input. Lay out variable values step by step — do not skip steps.

Example: Finding the Maximum

ALGORITHM FindMax(A)
    max  A[0]
    for i  1 to length(A) - 1 do
        if A[i] > max then
            max  A[i]
        end if
    end for
    return max

Manual trace on A = [3, 7, 2, 9, 4]:
| i | A[i] | max |
|—|------|-----|
| — | — | 3 |
| 1 | 7 | 7 |
| 2 | 2 | 7 |
| 3 | 9 | 9 |
| 4 | 4 | 9 |
Result: 9 ✓

Table of Contents