UNIHIVE

Study Hub UNIPORT CSC 183

CSC 183 · Introduction to Problem Solving

Algorithms and their properties

What makes a set of steps an algorithm, and how to judge one algorithm against another.

Our notes

2 min read

Definition

An algorithm is a finite, ordered set of clear instructions that solves a problem, taking inputs and producing outputs. The word comes from the ninth-century Persian mathematician al-Khwarizmi.

Properties of a good algorithm

  1. Finiteness: it stops after a finite number of steps.
  2. Definiteness: each step is clear and has only one meaning.
  3. Input: zero or more values are given to it.
  4. Output: at least one result is produced.
  5. Effectiveness: every step can actually be done (by hand, in principle).
  6. Correctness: it gives the right answer for every valid input.
  7. Generality: it solves a whole class of problems, not one case.

"Stir until it looks right" fails definiteness; "keep adding 1 until you reach the largest number" fails finiteness.

Example: the largest of a list

  1. Set LARGEST to the first number.
  2. For each remaining number: if it is greater than LARGEST, set LARGEST to it.
  3. Output LARGEST.

It has inputs, an output, clear steps, and stops after the last number.

Example: Euclid's algorithm for the HCF

To find the highest common factor of two whole numbers a and b:

  1. If b is 0, the answer is a. Stop.
  2. Otherwise, replace (a, b) by (b, remainder of a ÷ b) and go to step 1.

Worked example

HCF of 84 and 36:

  • (84, 36): 84 = 2 × 36 + 12 → (36, 12)
  • (36, 12): 36 = 3 × 12 + 0 → (12, 0)
  • b = 0, so HCF = 12.

Check: 84 = 12 × 7 and 36 = 12 × 3, and 7 and 3 share no factor ✓.

Comparing algorithms (efficiency)

Two correct algorithms can differ greatly in speed. To find a name in a sorted list of 1,000 names:

  • Linear search checks one by one: up to 1,000 checks.
  • Binary search checks the middle, then throws away half each time: at most 10 checks (2¹⁰ = 1,024).

We describe this growth with big-O notation: linear search is O(n), binary search is O(log n). Efficiency matters more as data grows.

Exams usually ask

  • State and explain the properties of an algorithm.
  • Write an algorithm for a simple task and trace it with given data.

Common mistake

Writing steps that depend on judgement ("pick a good number"). A computer needs an exact rule.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 183 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.