Algorithm

Context: FIT1008_MOC · a finite, halting recipe that solves a Computational Problem · the how to a problem’s what

Quick Revision

  • 🎯 Objective: finite well-defined instruction sequence ➔ maps each valid input to the correct output and always halts.
  • 📦 Core Components: Termination ➔ variant | Correct I/O ➔ invariant | Total correctness = both.
  • ⚡ Key Constraint: graded by asymptotic cost ➔ polynomial (tractable, P) vs exponential (intractable, NP-hard).

📝 Core

1. The Algorithm (Finite, Halting, Correct)

  • Core mechanism ➔ finite well-defined steps solving a Computational Problem ➔ correct output + always halts.
  • Two obligationsterminates on every instance AND correct input→output relation.
  • Many per problemLinear Search vs Binary Search ➔ same result, arbitrarily different cost.

2. Total Correctness (Partial + Termination)

  • Partial correctnessif it halts, holds ➔ proved by a loop Invariant.
  • Termination ➔ a variant (non-negative integer strictly decreasing) ➔ proves halting.
  • Total ➔ partial termination ➔ from any -state, halts in a -state.

3. Tractability & Determinism

  • Solvable ≠ efficient ➔ decidable yet possibly no efficient algorithm.
  • Class boundary ➔ polynomial = tractable (P) | only-exponential = intractable (NP-hard).
  • Randomised ➔ trade worst-case guarantee for strong expected cost (randomised Quick Sort).

⚙️ Core Implementation

🔹 Euclid’s algorithm — finite, halting, correct

⚖️ Core Decision Matrix

ConceptWhat it isOwnsExample
Computational Probleminput→output specificationlower bounds”find
Algorithmfinite, correct recipe solving itupper boundsEuclid’s algorithm
Instanceone concrete input

When It Flips: a specific algorithm sets an upper bound; the problem sets the lower bound (). When the algorithm's meets the problem's provably optimal.

📊 Exam Execution Trace

Manual Execution Trace

gcd(45, 30):

Step / StateTrigger OpabVariant bReturn Payload
0 (Init)init453030
1a,b = b, a%b301515
2a,b = b, a%b1500 → halt
3return a1515

Applied Exercise

Problem: State the obligations that establish total correctness of gcd. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: gcd is totally correct — invariant gives partial correctness, variant b gives termination.

🧠 Active Recall