UNIHIVE

Study Hub UNIPORT CSC 180.1

CSC 180.1 · Introduction to Computer Science and BASIC Programming

Algorithms, flowcharts and pseudocode

What an algorithm is, its properties, flowchart symbols, pseudocode and designing simple solutions.

Our notes

2 min read

Algorithm

An algorithm is a finite, ordered set of clear steps that solves a problem. Properties:

  • Finite: it ends after a number of steps.
  • Definite: each step is clear and has one meaning.
  • Input: zero or more inputs.
  • Output: at least one result.
  • Effective: each step can actually be done.

Flowchart symbols

SymbolMeaning
Oval (terminal)Start / Stop
ParallelogramInput / Output
RectangleProcess (calculation, assignment)
DiamondDecision (Yes/No)
ArrowsDirection of flow
Small circle (connector)joins parts of a chart

Rules: one start, one stop; flow top to bottom, left to right; each decision has two exits.

The three control structures

  1. Sequence: steps one after the other.
  2. Selection: choose a path (IF... THEN... ELSE).
  3. Repetition (loop): repeat while a condition holds or a set number of times.

Any algorithm can be written with these three.

Worked example 1: average of three numbers

Pseudocode:

  1. Start.
  2. Input A, B, C.
  3. S = A + B + C.
  4. AVG = S / 3.
  5. Print AVG.
  6. Stop.

For 4, 7, 10: S = 21, AVG = 7.

Worked example 2: largest of two numbers

  1. Input A, B.
  2. If A > B then print A, else print B.

For A = 12, B = 9, prints 12.

Worked example 3: sum of 1 to N (a loop)

  1. Input N.
  2. SUM = 0, I = 1.
  3. While I ≤ N: SUM = SUM + I; I = I + 1.
  4. Print SUM.

Trace for N = 5: SUM goes 1, 3, 6, 10, 15: prints 15 (check: N(N+1)/2 = 15 ✓).

Pseudocode

English-like steps, not a real language, easy to turn into code. Keep one action per line and indent the body of loops and decisions.

Dry running (tracing)

Make a table of variables and follow the steps by hand with test data. It finds logic errors before typing the program.

Exams usually ask

  • Define an algorithm and state its properties.
  • Draw a flowchart for a given problem (roots of a quadratic, grade from score, sum of a series).
  • Trace a given algorithm and give its output.

Common mistake

A decision diamond with only one exit, or a loop with no way to stop. Every loop needs a condition that eventually becomes false.

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 180.1 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.