Searchable browser preview of all 17 weekly Z5007 Python reference modules and the Course Project benchmark starter, paired with Big-O complexity summaries, Colab links, and LaTeX cheat sheets.
Topic:
Week 01O(1), O(log n), O(n), O(n log n), O(n^2)
Asymptotic Complexity & Log-Log Benchmarking
Reference Python implementation and self-checks for Z5007 Week 1.
Python Preview
import math
import random
import time
from typing import Callable
def constant_lookup(arr: list[int], index: int) -> tuple[int, int]:
"""Return (arr[index], step_count) in O(1) time."""
if not 0 <= index < len(arr):
raise IndexError("index out of range")
Reference Python implementation and self-checks for Z5007 Week 7.
Python Preview
import math
import random
from typing import Any, Optional
class AVLNode:
"""Node of an AVL tree caching subtree height for O(1) balance factor checks."""
def __init__(self, key: Any) -> None:
self.key = key
Week 11Kruskal & Prim O(E log V) · Interval Scheduling
Greedy Exchange & Minimum Spanning Trees
Reference Python implementation and self-checks for Z5007 Week 11.
Python Preview
import heapq
import random
from typing import Hashable
class DisjointSet:
"""Union-Find with path compression and union by rank."""
def __init__(self, items: list[Hashable]) -> None:
self.parent: dict[Hashable, Hashable] = {x: x for x in items}
Reference Python implementation and self-checks for Z5007 Week 13.
Python Preview
import bisect
import math
def matrix_chain_order(dims: list[int]) -> tuple[int, str]:
"""Return (min_scalar_multiplications, optimal_parenthesization) for matrix chain dims."""
n = len(dims) - 1
dp = [[0] * n for _ in range(n)]
split = [[0] * n for _ in range(n)]
for length in range(2, n + 1):
Week 163-SAT -> Independent Set · Vertex Cover 2-Approx
NP-Completeness, Reductions & 2-Approx
Reference Python implementation and self-checks for Z5007 Week 16.
Python Preview
from typing import Optional
def eval_cnf(clauses: list[tuple[int, ...]], assignment: dict[int, bool]) -> bool:
"""Evaluate a CNF formula where positive int x is x and -x is NOT x."""
for clause in clauses:
if not any((assignment[abs(lit)] if lit > 0 else not assignment[abs(lit)]) for lit in clause):
return False
return True
Reference Python implementation and self-checks for Z5007 Week 17.
Python Preview
import heapq
import math
import random
def monte_carlo_pi(samples: int, seed: int = 5007) -> float:
"""Estimate pi via randomized dart throwing in [0, 1]^2."""
rng = random.Random(seed)
inside = 0
for _ in range(samples):
Starter benchmark suite aligned with Z5007 Project Guidelines and Grading Rubric (600-node routing + 1,000-item Top-K catalog).
Python Preview
import math
import random
import time
class BinaryMinHeap:
"""From-scratch binary min-heap supporting O(log n) push and pop (no heapq dependency)."""
def __init__(self) -> None:
self._data: list[tuple[float, object]] = []