Skip to content

Algorithm flowchart and pseudocode

The logic of one algorithm, as a flowchart and as pseudocode.

What it explains and when it is useful

A flowchart shows the steps of one algorithm, its decisions and loops, using standard symbols. Pseudocode describes the same logic in structured text that is independent of any programming language.

When to use it: For every significant algorithm in your product. Flowcharts suit branching logic; pseudocode suits longer procedures and loops. Many students give both for the most important algorithm.

Worked example

Illustrative: PracticePal is a fictional project used throughout this guide.

Flowchart of PracticePal's make_booking algorithm: validate the slot, then check room blocks, clashes, the weekly cap of three and the loud-neighbour rule; if all pass, insert the booking inside a transaction; every rejection outputs a reasonSTARTINPUT student, room, start, loudSlot valid?(future, 07:30–17:30, :00 or :30)NoOUTPUT Invalid timeYesRoom blockedat that time?YesOUTPUT Room is blockedNoOverlaps a bookingfor this room?YesOUTPUT Slot taken: offerwaiting listNoStudent already has3 bookings that week?YesOUTPUT Weekly limitreachedNoloud AND a neighbourroom has a loud bookingthat overlaps?YesOUTPUT Noise clash withneighbour roomNoBEGIN IMMEDIATE transactionINSERT booking (status = confirmed)Insert succeeded?(no UNIQUE violation)NoOUTPUT Slot just taken(ROLLBACK)YesCOMMIT; OUTPUT “Booked” + bookingENDevery rejectionjoins the END
make_booking: the algorithm behind SC4–SC6.

Scroll sideways to see the whole diagram.

Pseudocode

FUNCTION make_booking(student, room, start, loud)
    // SC4–SC6: every check must pass before anything is saved
    end ← start + 30 minutes
    IF NOT valid_slot(start) THEN RETURN "Invalid time"
    IF room_blocked(room, start, end) THEN RETURN "Room is blocked"
    IF overlapping_bookings(room, start, end) > 0 THEN
        RETURN "Slot taken"                      // the page then offers the waiting list (SC7)
    END IF
    IF bookings_in_week(student, week_of(start)) ≥ 3 THEN RETURN "Weekly limit reached"
    IF loud THEN
        FOR EACH n IN neighbours[room]           // dictionary: room → set of rooms
            IF loud_bookings(n, start, end) > 0 THEN RETURN "Noise clash with " + n
        END FOR
    END IF
    BEGIN IMMEDIATE TRANSACTION                  // lock first, so two requests cannot both pass
        repeat the overlap check
        INSERT booking(student, room, start, end, loud, "confirmed")
    COMMIT, or ROLLBACK and RETURN "Slot just taken" if the insert fails
    RETURN booking
END FUNCTION

overlap rule: booking A overlaps B when A.start < B.end AND B.start < A.end
PROCEDURE offer_next(room, slot)              // SC7, called when a booking is cancelled or released
    entry ← first WAITING entry for (room, slot) ORDER BY joined_at   // queue: first in, first out
    IF entry = NULL THEN RETURN                  // nobody waiting: the slot simply becomes free
    entry.state ← "offered";  entry.offered_at ← now
    send offer to entry.student (link expires in 15 minutes)
END PROCEDURE

PROCEDURE every_5_minutes(now)                   // run by the scheduler
    FOR EACH booking WHERE status = "confirmed" AND start + 10 min < now AND NOT checked_in
        booking.status ← "no_show";  offer_next(booking.room, booking.start)        // SC8
    FOR EACH entry WHERE state = "offered" AND offered_at + 15 min < now
        entry.state ← "expired";  offer_next(entry.room, entry.slot)                // SC7
END PROCEDURE

Notation and legend

Symbol or partMeaning
Rounded terminatorSTART / END
ParallelogramInput or output
RectangleProcess
DiamondDecision with labelled exits (Yes / No)
ArrowsFlow of control

Design decisions it communicates

A diagram earns marks when you explain the decisions it shows. In PracticePal's documentation these would each be one sentence:

  • The cheap checks come first; the transaction comes last so the lock is held briefly.
  • Every rejection outputs a reason, which becomes the error message (SC5, SC6).
  • The overlap check is repeated inside the lock, which is what prevents double bookings.

Common mistakes

  • Copying code into boxes: describe the logic, not the syntax.
  • Unlabelled decision exits.
  • Drawing the whole program as one flowchart.
  • Calling a data flow diagram a flowchart.
Often confused with: Data flow diagram. A flowchart is about the order of steps and decisions in one algorithm. A DFD is about where data moves between processes, stores and external entities, with no order or decisions.

Checklist for your own version

Ticks are saved in this browser only, so you can use the list while you draft.