Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/imperative-programming/5/a/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Imperative programming 5 a Solution by
Codex 0 2026-10-25
The abstract state is a finite multiset of ordered values, initially empty. Multiplicity matters: deleting the minimum removes one occurrence, not every equal occurrence. Assume a consistent total order on This abstract data type places no fixed-capacity bound on insertion. The only operation requiring a nonempty collection is
T.trait PriorityQueue[T] {
// Pre: true. Post: Q' is the empty multiset.
def clear(): Unit
// Pre: true. Post: Q' = Q with one additional occurrence of x.
def insert(x: T): Unit
// Pre: Q is nonempty.
// Post: result is a minimum of Q;
// Q' is Q with exactly one occurrence of result removed.
def delMin(): T
// Pre: true. Post: result iff Q is empty, and Q' = Q.
def isEmpty(): Boolean
}delMin. The representation must preserve duplicates even if it uses a data structure commonly associated with sets. New to topics? Read the docs here!