All subjects · Computer Science · Unit 4

WCP04 Advanced Practical Programming and Problem-solving

Edexcel IAL Computer Science, Unit 4 (A2 unit, usually Year 13). 28 lessons so far, in the suggested order.

Practise this unit in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise in the app

Lessons in WCP04

  1. Operators and control flow constructs
    / gives a float, // rounds down, % gives the remainder; & | ^ ~ << >> work on bits; match/case with case _ as the default; for for a known count, while for an u
  2. Data types, variables, constants and type conversion
    int, float, str, bool; type() checks; int() truncates; int('3.7') fails; only empty values are False; round() halves to even; constants in UPPER_CASE.
  3. One- and two-dimensional data structures
    list (mutable, ordered), tuple (immutable), dict (key to value), set (unique, fast membership), str (immutable). grid[r][c]; build 2D lists with a comprehension
  4. Computational thinking, IDEs and debugging tools
    Decompose, abstract, spot patterns, write exact steps. Trace tables predict output. Read tracebacks from the last line up; use breakpoints, stepping and watches
  5. Subprograms, modules, libraries and text files
    Functions return values, procedures do not; prefer parameters and return values to globals. import modules; math, random, copy, time from the PLS. Files: 'r', '
  6. Floating-point data and the decimal module
    Floats are binary approximations; Decimal('0.1') is exact. quantize to round (default half-even, ROUND_HALF_UP on request); getcontext().prec sets significant f
  7. Regular expressions: finding and validating text
    Raw strings; \d \w \s, [sets], * + ? {m,n}, | and groups; search finds the first match, fullmatch validates, findall lists, sub replaces, split splits; Match.gr
  8. Numerical data with NumPy arrays
    np.array with a type code; shape, reshape; a[r, c], a[:, c], a[a > x]; arithmetic and comparisons work element by element; sum/mean/std/var with axis=0 (columns
  9. Data analysis with pandas
    read_csv into a DataFrame; shape, head, tail, info, describe; Series mean, median, mode, std, value_counts; clean with dropna and duplicated; sort_values; iloc
  10. Implementing a circular queue in a fixed-length list
    Fixed-length list plus front, rear and size; move a pointer with (p + 1) % capacity; empty when size == 0, full when size == capacity; check before enqueue and
  11. Implementing a linked list with classes
    Node(data, next); list holds head; traverse by following next until None; insert by linking new.next first, then the previous node's next; remove by making the
  12. Hash tables and hash algorithms
    hash(key) gives the slot index directly; good hashes are deterministic, fast and even; sum of codes makes anagrams collide, a polynomial hash does not; prime ta
  13. Handling collisions: chaining, linear probing and rehashing
    Chaining: each slot holds a list. Linear probing: step to (i + 1) % size; find stops at an empty slot; delete with a tombstone. Rehashing: when the load factor
  14. Representing graphs: adjacency matrix and adjacency list
    Undirected, directed, weighted; matrix[i][j] = weight (n2 cells, instant edge test, good for dense graphs); adjacency list as a dict of dicts (memory per edge,
  15. Implementing a binary search tree
    Node(data, left, right); smaller values go left, larger go right; insert by walking to an empty reference; find follows the same path; first value is the root a
  16. Recursive tree traversals: pre-order, in-order and post-order
    Pre-order: node, left, right. In-order: left, node, right (sorted for a BST). Post-order: left, right, node. Base case: an empty subtree does nothing.
  17. Designing programs: decomposition, modularity and scope
    Decompose into focused subprograms; pick fitting types, structures and constructs; keep input, processing and output separate; minimise side effects and globals
  18. Clean code: consistency, readability and controlling behaviour
    PEP 8 consistency (4 spaces, snake_case, CapWords, UPPER_CASE, fixed line length); meaningful names, named constants and purposeful comments; guard clauses to r
  19. Testing, debugging, reviewing and refining
    Syntax errors stop the program running; run-time errors raise exceptions (NameError, AttributeError, TypeError...); logic errors give wrong results. Test normal
  20. Object-oriented programming: classes, objects and encapsulation
    A class is a blueprint; __init__ sets attributes; self is the current object; methods are functions in the class; class attributes are shared. Encapsulation: _p
  21. Inheritance, polymorphism, aggregation, composition and UML
    Subclass(Parent) inherits; super().__init__ reuses the parent constructor; overriding replaces a method; polymorphism: the same call runs each object's own meth
  22. Functional programming: pure functions, higher-order functions and comprehensions
    Pure functions: same inputs, same output, no side effects; return new values instead of mutating; functions are first-class; higher-order functions take or retu
  23. Lazy evaluation and generators
    yield makes a generator; next() runs to the next yield and pauses; StopIteration when finished; generator expressions use round brackets; values are computed on
  24. Implementing a recursive merge sort
    Base case: 0 or 1 items. Split at mid = len // 2, merge sort each half, merge by taking the smaller front item; extend with leftovers. O(n log n) always, O(n) e
  25. Implementing a recursive quick sort
    Choose a pivot, partition into smaller, equal and larger, recurse on the parts and join. Average O(n log n); worst O(n2) with a bad pivot (such as the first it
  26. Implementing Dijkstra's shortest path algorithm
    Distances start at infinity (start 0); repeatedly settle the closest unvisited vertex; relax each neighbour: update if current + weight is smaller and record pr
  27. Implementing run-length encoding
    Count each run; on a change store (value, count) and restart; store the final run; decode by repeating; lossless; great for long runs, worse than the original w
  28. The Unit 4 on-screen exam: how it works and how to tackle it
    3 hours, 80 marks, 5 compulsory questions, Python 3 in an IDE, no AI or internet, PLS provided; save to the named file and never overwrite originals; tasks rang