about COMPSCI220
0 · Exam Mapcourse.json · brief
| Component | Weight | Format / role |
|---|---|---|
| Practical Component | 15% | quiz, written/programming assignments, tutorial presentations; must be passed |
| Tests | 35% | two midterm tests; theory component |
| Final Examination | 50% | comprehensive theory assessment covering the full course |
Permitted materials: not confirmed for this offering in the course materials we hold — check the exam instructions on the LMS. Source: BRIEF.md
The pass structure has three checks: pass the practical component, pass the theory component formed by tests and examination, and pass overall. Treat the final as a course-wide test of moving between representation → trace → correctness → growth.
Priority grid — what a complete response contains
| Cluster | Observable work | Boundary to say aloud |
|---|---|---|
| Asymptotics | define n; count; exhibit c,n₀; verify inequality | upper bound need not be tight |
| Correctness | state invariant; show state before/after a step | examples do not prove correctness |
| Sorting | trace subproblems and merge; justify recurrence | check worst case, memory, stability |
| Trees | execute insertion/removal; show affected path | running time follows actual height |
| Hashing | calculate location and α; trace each collision | expected cost needs assumptions |
Six-line answer audit
| 1 Input | Have I named the representation and input-size variable? |
|---|---|
| 2 State | Can a marker see the relevant state before the operation? |
| 3 Condition | Is the comparison, invariant or ordering rule explicit? |
| 4 Update | Did I show exactly what changes and what stays fixed? |
| 5 Cost | Does the growth claim follow from counted work or height? |
| 6 Limit | Did I name the assumption that prevents overclaiming? |
1 · Asymptotic AnalysisC1 · final theory
Asymptotic analysis studies how time or space grows with input size while ignoring fixed implementation constants. Name the input variable n and the counted operation before naming a class.
Big-O definition · bound proofT(n) ∈ O(g(n)) ⇔ ∃ c,n₀ > 0:
0 ≤ T(n) ≤ c·g(n) for every n ≥ n₀
| Claim | What must appear | Boundary |
|---|---|---|
| T ∈ O(g) | exhibit c and n₀; verify the inequality | eventual upper bound |
| Correct loop | state invariant; trace state change; connect to result | tests alone are not proof |
| Scales as claimed | operation count + input variable | constants abstracted away |
Correctness via a loop invariant
A loop invariant is true before and after each iteration and supports the result. Before executing, record the relevant state; for each operation show the branch or iteration, state before/after, and what output depends on it. Check a normal, boundary and invalid input, but keep the logical distinction: matching examples do not constitute proof.
| Trace field | Question it answers | What not to omit |
|---|---|---|
| Object | What value, structure or cost is analysed? | input variable and representation |
| Control | Which branch, iteration or call follows? | the condition selecting it |
| Before / after | What state transition occurred? | unchanged state that preserves the rule |
| Invariant | What proposition survives every iteration? | connection from preserved fact to result |
| Operation count | How does work grow with n? | the operation actually being counted |
Safe conclusion language
Bound: “For the exhibited positive constants, the inequality holds from n₀ onward, so T(n) has the stated eventual upper bound.” Correctness: “The stated proposition is preserved by the iteration and supports the required result.” These are different claims; proving either one does not silently prove the other.
2 · Sorting + RecurrencesC2 · trace + cost
A comparison sort bases ordering decisions on comparisons between keys. Trace the subproblems and merge, then justify the cost. Keep correctness/order properties separate from time and memory claims.
Merge-sort recurrence · cost responseT(n) = 2T(n/2) + c·n ∈ Θ(n log n)
| Term / property | Meaning in the answer |
|---|---|
| 2T(n/2) | two half-size recursive subproblems |
| c·n | linear merge work; not another recursive call |
| Θ(log n) levels | repeated halving to base cases |
| Θ(n) per level | linear work across a complete level |
| stability | equal keys retain their relative order |
Decision rule
If the prompt asks for a trace, show subproblem states and the merge result. If it asks for cost, identify both recursive and non-recursive terms, then connect levels × work per level. If it asks whether the sort is suitable, check worst-case input, memory cost and required stability; asymptotic or average performance does not erase them.
| Line of working | What to write | Self-check |
|---|---|---|
| Input | the sequence and comparison key | are equal keys distinguishable as records? |
| Divide | each half-size subproblem | does the trace match 2T(n/2)? |
| Combine | linear merge work across the level | is cn kept outside the recursive term? |
| Levels | repeated halving gives logarithmic depth | is work per whole level linear? |
| Order property | relative order of equal-key records | is the required stability preserved? |
| Conclusion | Θ(n log n) for this relationship | have worst case and memory been ignored? |
Stability test: attach identity to records sharing a key, then inspect their relative order after the merge. A sorted sequence can still fail a stability requirement. Keep the stability observation alongside, not inside, the recurrence calculation.
3 · Heaps + Search TreesC3 · operation trace
A heap is a complete-tree structure with parent–child ordering for extreme-priority operations. A binary search tree orders every node against keys in its left and right subtrees. These structures answer different questions: a heap exposes an extreme; a search tree organises ordered search.
Zero-based array heap · index traceleft(i) = 2i + 1 right(i) = 2i + 2
candidate index only → verify index < array length
| Structure | Shape / order evidence | Cost control |
|---|---|---|
| Heap | complete-tree shape + parent–child order | path through its height |
| BST | left/right subtree key relation | actual tree height |
| Degenerate BST | insertion order stretches the tree | do not claim logarithmic height |
Trace insertion or removal
- State the representation and ordering rule.
- Show the affected index/node before and after each move.
- Stop only when the required relation is restored.
- Relate the number of moves to structural height.
| Operation evidence | Heap | BST |
|---|---|---|
| Starting state | array length, index, parent–child order | root and left/right key relation |
| Next move | compare only existing candidate children | follow comparison into one subtree |
| Changed state | show each moved entry and index | show link/node affected by insert/remove |
| Stop rule | required parent–child relation restored | target found or insertion position reached |
4 · Hashing + CollisionsC4 · table-state trace
A hash function deterministically maps a key to an integer used to choose a table location. A collision means multiple keys map to the same location; a collision strategy must determine how insertion and retrieval proceed.
Load factor · occupancy responseα = n / m
n = stored entries · m = table capacity
| Stage | Record explicitly | Reason |
|---|---|---|
| Hash | key → computed location | shows deterministic placement |
| Collision | occupied location + competing keys | activates the stated strategy |
| Resolve | every location examined or link followed | makes expected access cost traceable |
| Load | stored entries / capacity | connects occupancy to collision pressure |
What the conclusion may say
Expected collision and lookup behaviour depends on the collision method and hash-quality assumptions. Constant expected lookup is conditional: it does not mean every operation is constant in the worst case. Chaining and open addressing deteriorate differently, so do not interpret α without the stated collision method.
| Wrong shortcut | Repair |
|---|---|
| α = occupied buckets / entries | α = stored entries / capacity |
| “hashing is O(1)” | state expected claim + hashing/resizing assumptions |
| show final table only | show collision path and resulting state |
Trace ledger — one row per inserted key
| Column | Record | Why it matters |
|---|---|---|
| Key | the current key only | preserves insertion order |
| Hash result | initial table location | separates mapping from resolution |
| Observed state | empty, matching key, or collision | shows why the next rule fires |
| Resolution path | every slot examined or link followed | makes access work visible |
| Resulting table | state after this insertion | becomes the next row’s input |
5 · Traversal + ComponentsC5 · reachability trace
A graph representation records vertices and edges, for example with adjacency lists or a matrix. Breadth-first search explores vertices in nondecreasing unweighted distance from a start vertex.
First BFS discovery · distance traced(v) = d(u) + 1 when v is first discovered from u
record predecessor u · enqueue v once
| Need | Do | Qualification |
|---|---|---|
| Traversal | show queue/discovery order from given adjacency order | order can change with adjacency order |
| Distance | assign predecessor distance + 1 on first discovery | unweighted edge count |
| Component | collect all vertices reachable under direction rules | maximal reachable set |
Connected component: a maximal set of vertices mutually reachable by paths under the graph’s direction rules. A different adjacency order may change the discovery tree or predecessor, but not the shortest unweighted edge counts.
6 · Weighted OptimisationC6 · compare objectives
Relaxation · shortest-path traced(v) ← min{d(v), d(u)+w(u,v)}
update predecessor only when the candidate is cheaper
| Object | Definition / condition |
|---|---|
| Shortest path | minimum total edge weight among paths allowed by the model and algorithm assumptions |
| MST | minimum-total-weight acyclic set connecting every vertex in a connected undirected graph |
| Dijkstra condition | non-negative edge weights for its finality claim |