COS332 StudyGuide Routing Encodings (1)
COS332 StudyGuide Routing Encodings (1)
This guide covers two core COS332 exam topics in depth. Part 1–3 cover routing algorithms (Dijkstra and Bellman-Ford)
with fully worked examples, visual diagrams, and exam tips. Part 4–6 cover character encodings (ASCII, EBCDIC,
Unicode, UTF-8) with conversion techniques, visual aids, and calculator instructions.
Section Topic
Algorithm type Greedy Always picks the nearest unvisited node — never revisits
Approach Centralised Needs a complete map of the network (LSDB) before it can run
Adaptability Static / non-adaptive Cannot react to changes without re-running from scratch
Used in protocol OSPF (IGP) Routers flood topology info; each runs Dijkstra locally
OSI Layer Layer 3 — Network Determines the routes used to forward IP packets
Time complexity O(V²) basic Fast for typical network sizes; O(E log V) with a heap
S (confirmed set) The set of nodes whose shortest path from the source is FINALISED. Once in S, never
updated again.
Tentative cost The best-known distance to a node so far. May still improve until the node joins S.
∞ (infinity) Initial cost for all nodes except the source. Means "not yet reachable".
Next hop The first node on the shortest path toward the destination — this is what the routing table
stores.
Round number i Round i starts when |S| = i. Round 1 always starts with just the source node in S.
1. Initialise Source cost = 0. All others = ∞. S = { source }. Record next hop = source for source.
2. Update For each neighbour N of the node just added to S: candidate = cost(current node) + link_weight(to N) If
neighbours candidate < N's current tentative cost → update N's cost and next hop.
3. Select From all nodes NOT in S, find the one with the SMALLEST tentative cost. Add it to S. Its cost is now
next node FINAL.
4. Repeat Go back to Step 2, using the newly added node. Continue until S contains all nodes.
5. Read Follow the next-hop pointers from source to reconstruct any shortest path.
paths
E–G 7
F–G 9
Figure 1: Network graph. Green edges = shortest paths found by Dijkstra. Numbers in nodes = final cost from A.
Dijkstra trace — running from source A. Each column shows the tentative cost after that round. The node in bold on
the right is added to S that round (its cost is now final).
Approach Distributed Each router shares its table with direct neighbours only — no global
map needed
Adaptability Adaptive Automatically reacts when routing tables change due to topology shifts
Negative costs? YES (with limits) Handles negative link costs but NOT negative-weight cycles
Used in protocol RIP (IGP) Each router periodically broadcasts its full table to neighbours
OSI Layer Layer 3 — Network Builds the distributed routing tables that guide packet forwarding
Main weakness Count to infinity When a link fails, costs can slowly spiral upward — converges very
slowly
2. Share Routers periodically send their FULL routing table to ALL direct neighbours.
tables
3. Update on When D receives a table from neighbour N, for each destination X: candidate = cost(D→N) +
receipt N's_cost(X) If candidate < D's current cost to X → UPDATE: set D's cost=candidate, next hop=N
4. Repeat Keep exchanging and updating. After enough rounds, all tables converge to correct values.
5. Watch for If a cost keeps increasing indefinitely after a failure → count-to-infinity problem (see 2.5).
loops
A 10 B A 20 E A 15 F
A 2 B C 3 C D 4 D
D 3 D E 4 E F 5 F
G 8 E G 5 F
Derived link costs: D↔C = 3 (C's table shows D at cost 3 next hop D — so D is directly connected to C at cost 3). D↔E = 4
(D's table shows E at cost 4 next hop E).
Dest X D's current cost Via C: cost(D,C) + C's Better? Action on D's table
to X cost(X)
(a) Entry for A after C's table A | cost 13 | next hop C cost(D,C)+C's A = 3+10 = 13 < 20 ✓
(b) Entry for B after C's table No entry — B is unreachable C has no route to B; D cannot learn
B from C
Dest X D's current cost to Via E: cost(D,E) + E's Better? Action on D's table
X cost(X)
(c) Entry for F after E's table F | cost 9 | next hop E D had no F; 4+5=9 — new entry
added
(d) Entry for G after E's table G | cost 8 | next hop E 4+5=9 is NOT less than 8 — no
(unchanged) update
Before cost=1 via A cost=2 via B Correct. A–B link works fine.
failure
A–B link ∞ (link down) cost=2 via B B knows A is gone. C does NOT know yet.
fails! (STALE — old info)
B reads C's cost=3 via C cost=2 via B (still B thinks: C says A=2, so I'll go C at 1+2=3. LOOP!
table stale)
C reads B's cost=3 via C cost=4 via B C updates: B says A=3, so 1+3=4. Both looping!
table
...continues cost=5 via C cost=6 via B Costs keep climbing: 5→7→9... until max (16=∞ in RIP)
...
Solutions to count-to-infinity: (1) Split horizon — do not advertise a route back toward the neighbour you learned it from. (2)
Poison reverse — advertise the route back but with infinite cost. (3) Maximum hop count — RIP uses 16 as infinity; any cost ≥
16 = unreachable.
Algorithm type Greedy — picks minimum each round Dynamic programming — iterates edges
Information needed Full network map (LSDB — all links) Only direct neighbours' routing tables
Centralised or distributed? Centralised (full map → run locally) Distributed (each node ↔ neighbours)
Handles negative link costs? NO — all costs must be ≥ 0 YES — but not negative-weight cycles
Speed of convergence Fast — O(V²) or O(E log V) Slower — O(VE) worst case
Reacts to link failure? Only after topology update + re-run Adapts via updates (risk: count-to-∞)
Routing info exchanged LSAs (full topology advertisements) Distance vectors (just routing tables)
Scales well? Yes — OSPF uses areas to limit scope Poor — table size grows with network
Memory requirement High — needs full LSDB in RAM Low — only neighbour tables needed
Main weakness Needs full topology; complex flooding Count-to-infinity on link failure
Memory Aid: Dijkstra = Determined (needs full map, one-shot greedy). Bellman-Ford = Back-and-forth (distributed, adaptive,
keeps updating neighbours).
PART 4 — Character Encodings: ASCII, EBCDIC, Unicode, UTF-8
From the COS332 textbook (Prof MS Olivier): "While most computers use some superset of ASCII to encode characters, not all
do... If two computers use different character encoding schemes they will obviously not be able to communicate directly with one
another." — Character encoding is a Presentation Layer (OSI Layer 6) concern.
Figure 3: ASCII character map. Top row shows each character; bottom shows its decimal code. Colour-coded: green=uppercase,
pink=lowercase, blue=digits, orange=punctuation.
ESC (escape) 27 0x1B Used in ANSI escape codes for terminal control
Digit '0' 48 0x30 '0'=48. Add digit value: '5'=53. Subtract 48 to get number.
DEL (delete) 127 0x7F Last ASCII character. All 7 bits = 1111111
Char ASCII dec EBCDIC dec EBCDIC Char ASCII dec EBCDIC dec EBCDIC
hex hex
Textbook example: GET in ASCII = [71, 69, 84]. GET in EBCDIC = [199, 197, 227]. There is NO formula — you must
use a lookup table. Note the I–J gap: I=0xC9 (201) but J=0xD1 (209) — eight values are skipped!
Code point The unique number for a character. Written U+XXXX. Example: U+0041 = Latin
capital A
BMP (Basic Multilingual Plane) Plane 0: U+0000–U+FFFF. All common scripts. Fits in 16 bits.
Supplementary planes Planes 1–16: U+10000–U+10FFFF. Emoji, historic scripts, rare ideographs.
Code unit The basic storage element of an encoding. UTF-8 uses 8-bit units; UTF-16 uses
16-bit units.
Surrogate pair UTF-16 mechanism for supplementary chars: two 16-bit code units (0xD800–0xDFFF
range).
BOM (Byte Order Mark) U+FEFF at file start — signals encoding type and byte order. UTF-8 BOM = EF BB
BF.
Unicode ≠ UTF-8 Unicode = the standard assigning numbers. UTF-8 = one way to store those numbers
as bytes.
Code Point Range Decimal Range Bytes 1st Byte Pattern Remaining Bytes
Rule Description
1-byte = ASCII If the first (and only) byte starts with 0 → single-byte character, identical to ASCII.
Count leading 1s The number of leading 1-bits in the first byte tells you the total byte count. 110... = 2, 1110... =
3, 11110... = 4.
Continuation bytes Every continuation byte (bytes 2, 3, 4) ALWAYS starts with 10xxxxxx (values 128–191).
Self-synchronising You can always find the start of a character: look for any byte that does NOT start with 10.
No byte-order issue Unlike UTF-16, UTF-8 has no byte-order ambiguity — no BOM needed for identification.
Min bytes/char 1 2 4
Max bytes/char 4 4 4
Property UTF-8 UTF-16 UTF-32
Byte order issues? None — byte order YES — needs BOM (LE/BE) YES — needs BOM
irrelevant
Best used for Web, files, APIs, email Windows/Java/JS internals Specialised — very
memory heavy
Internet dominance >98% of web pages (2024) Rare on web Extremely rare
PART 5 — Conversions: By Hand and on a Calculator
5.1 Decimal ↔ Hexadecimal — The Foundation
Conversion Method Worked Example
Hex → Decimal Multiply each digit by its power of 16 (right to left: 0x41: (4 × 16¹) + (1 × 16■) = 64 + 1 = 65 ✓
16■, 16¹, 16²...) Then add all products.
Decimal → Binary Divide by 2 repeatedly. Remainders (bottom to 65 → 0x41 → 0100 0001 Verify: 64+1 = 65 ✓
top) = binary. OR: convert to hex first, then each
hex digit → 4 bits.
Binary → Decimal Multiply each bit by its power of 2 (right to left). 01000001: 2■+2■ = 64+1 = 65 ✓
Add all non-zero terms.
Char → Hex Get decimal first, then ÷16 'A'=65 → 65=4×16+1 → 0x41
Hex → Char Convert hex to decimal, use formula 0x61 = 6×16+1 = 97 = 'a'
above
3. Range check 128–2047 → 2 bytes, pattern: 110xxxxx 10xxxxxx 11 payload bits needed
Step Working Result
5. Split into First 5 bits: 00010 | Last 6 bits: 100011 00010 | 100011
groups
2. Identify C3 starts with 110 → 2-byte sequence Extract payload from both
sequence bytes
3. Extract 110[00011] → take: 00011 10[110110] → take: 110110 00011 and 110110
payload bits
Enter BASE-N Press MODE → select BASE (option 3, 4, or 5 depending DEC HEX BIN OCT labels appear
mode on model)
Set to Decimal Press the DEC softkey (F2 or similar) DEC indicator lights up
input
Decimal → Hex Type decimal number → press HEX softkey Result shown in hexadecimal
Decimal → Binary Type decimal number → press BIN softkey Result shown in binary
Hex → Decimal Press HEX mode → type hex digits (A–F available) → Decimal result shown
press DEC
Hex → Binary Press HEX mode → type hex → press BIN Binary result — use this for UTF-8
patterns!
fx-991EX Press MENU → option 5 (Base-N) → use softkeys to Cleaner display with more digits
CLASSWIZ switch bases
ASCII values No built-in function — MUST memorise key anchor A=65, a=97, 0=48, Space=32
points
Exam workflow for UTF-8: 1. Find decimal code point. 2. Use calculator BIN mode to get binary. 3. Apply UTF-8 pattern
manually (split bits, add markers). 4. Use calculator HEX mode to verify your byte values.
PART 6 — Quick Reference Tables & Exam Tips
6.1 Essential ASCII Values — Memorise These Anchors
Char Dec Hex Char Dec Hex Char Dec Hex
LF 10 0A '@' 64 40 '9' 57 39
CR 13 0D 'A' 65 41 'a' 97 61
EBCDIC 1964 8 256 IBM mainframes only. Letters NOT contiguous — no formula.
ISO 8859-1 1987 8 256 Western Europe. Extends ASCII with accented chars.
UTF-16 1996 16–32 1.1M+ Windows/Java internals. Surrogate pairs for Plane 1+.
UTF-32 1996 32 1.1M+ Fixed width, simple — but 4× memory vs UTF-8 for ASCII.
Round S contains Node just added Cost Updates made to tentative costs
n {all nodes} last node ??? Done — all shortest paths found
1 Dijkstra Confusion about which round adds which Round i STARTS with |S|=i. Node added "from
rounds node round 3 to 4" is finalised at round 4.
2 Dijkstra initial "Initial cost to C during round 1" includes Round 1 initial cost = DIRECT link only. Indirect
cost indirect paths paths discovered in later rounds.
4 BF next hop Setting next hop to the final destination Next hop = the NEIGHBOUR who sent you the
table. Always.
5 BF update rule Updating when new cost equals current Only update if STRICTLY LESS THAN. Equal cost
cost → no change.
6 ASCII '0' Thinking digit 0 has ASCII value 0 '0' = 48, NOT 0. Digits 0–9 = ASCII 48–57.
7 Unicode vs Using them interchangeably Unicode = character set (assigns numbers). UTF-8
UTF-8 = encoding (stores bytes).
8 UTF-8 1-byte Not knowing where single-byte ends Exactly U+0000–U+007F (0–127). Same as
range ASCII. U+0080 needs 2 bytes.
9 EBCDIC Trying to calculate EBCDIC from ASCII Impossible — EBCDIC has no formula. Letters are
formula arithmetically NOT contiguous. Use lookup table.
10 HTTP 406 Confusing character encoding rejection Encoding mismatch (Accept-Charset failure) →
with 404 406 Not Acceptable. 404 = resource not found.
Textbook Reference (Prof MS Olivier, COS332): GET in ASCII = [71, 69, 84]. GET in EBCDIC = [199, 197, 227]. GET in
Fieldata = [12, 10, 25]. HTTP 406 = server cannot encode response in any of the client's requested character encodings. Dijkstra
characteristics: greedy, static/non-adaptive, centralised. Bellman-Ford characteristics: distributed, adaptive. Problem:
Count-to-infinity.