Solutions to all three questions of the University of Oxford computer science finals paper, Trinity Term 2018, held on 16 June 2018. Every printed option is treated.
Source: Public examination-paper archive, member
2017/T/a16156w1.pdf, paper A16156W1, three scanned pages. The printed 2018 cover controls the sitting despite the archive member’s directory name.A binary search tree is a binary tree storing distinct keys from a total order, with every key in a node's left subtree smaller than that node's key and every key in its right subtree larger. The condition concerns entire subtrees, not just immediate neighbours.
For membership, start at the root of a tree and compare the target with the current key. Return true on equality; continue into the left subtree for a smaller target and the right subtree for a larger target; return false on an empty subtree. The binary search tree ordering ensures that a discarded subtree cannot contain the target. Each step descends one level, so the algorithm terminates and uses time complexity for height of a binary tree , under constant-time key comparison.
First perform splaying on the key to be deleted, making its node the root of a tree. Delete that root, leaving left and right subtrees . If either is empty, return the other. Otherwise find the maximum key of by following right-child references, and perform splaying on within . This makes the root of with an empty right subtree. Attach there. The result is the original splay tree with exactly the selected key removed. An unsuccessful lookup leaves the represented set unchanged.
For algorithm correctness, all keys of are smaller than the deleted key, and all keys of are larger. Splaying preserves the binary search tree property by the permitted assumption. Since is the maximum of , it has no larger key within ; since every key of exceeds , attaching as its right subtree preserves every ordering condition. All remaining keys occur once. This is the join-based deletion of a splay tree.[ref]
Self-Adjusting Binary Search Trees by Daniel Sleator and Robert Tarjan. Author-hosted publication record and abstract: splay-tree search, insertion and deletion operations
No. In a red-black tree with no red nodes, equal black height forces every graph path from the root to an absent-child position to have the same length. A real node cannot have exactly one real child: the two paths through that node would then have different numbers of black nodes. Recursively, every real level must be full. The tree is therefore a perfect binary tree.
With real levels its size is . A size of would require , which is impossible for an integer . The black null sentinels are not counted among the stored entries. This is the all-black red-black tree size criterion.
Use the conventional bottom-up red-black tree insertion: insert a red node by the binary search tree rule, repair a red parent with recolouring or tree rotations, and make the root black. Write and for black and red. The first three insertions give root , with on the left and on the right.
Inserting as the left child of gives a red parent and a red uncle. Recolour black and retain a black root . Inserting then gives the inner configuration ––. A left tree rotation at , followed by a right tree rotation at , produces a subtree rooted at with and beneath it. Finally insert to the left of . Its uncle is red, so recolour black and red. No further repair is required because has black parent .
The final root is ; its left child is and its right child is . Under are on the left and on the right; has left child . All omitted children are black null sentinels. Each root-to-null graph path has two real black nodes, and no red node has a red child.
Write . After splaying on , that key is at the root, and is the smallest key in its right subtree. This uses the integer assumption: no stored key lies strictly between and . Thus has an empty left subtree while it remains within the right subtree of .
Now perform ordinary bottom-up splaying on . Until the final step involving , all tree rotations occur below and leave it at the root. There are only two possible final cases.
- If is the right child of , a single zig step rotates above , placing immediately to its left.
- Otherwise is a grandchild of . Its parent lies in the right subtree of and must satisfy . Hence the last two directions are right then left. A zig-zag step rotates above and then above , again placing immediately to its left. A right-right final configuration is impossible because is the minimum of this subtree.
Therefore becomes the left child of . The argument applies more generally to consecutive keys in a binary search tree, even when their numerical difference is not one.
Use the usual bottom-up splaying operations. We prove the stronger result that at most three successful calls suffice. No insertions or deletions are needed.
If the chosen key is the minimum stored key, first perform splaying on and then on its immediate successor. The argument for consecutive keys in a binary search tree makes the left child of the successor with an empty right subtree; minimality makes its left subtree empty too. Hence is a leaf of a rooted tree. The maximum-key case is the mirror image.
Suppose is an interior key. Since at least four keys are stored, there are either two keys larger than or two smaller than . In the former case choose four consecutive stored keyswhere is the predecessor of , and are the next two successors. Perform .
Here is a complete check of the local shapes. After the first call, is the root. After the second, is the root; every key below is in its left subtree , and every key above stays in the right subtree of . These outside subtrees cannot interfere with the next search. Between and there are only . The last step of splaying on is either a zig step, leaving as its right child; a zig-zag step, with the same result; or a zig-zig step, leaving some as its right child with immediately to the right of . Consequently the possible right subtrees of are exactly among these four forms, using for a node with its left and right subtrees:Here an unexpanded or denotes a node with no children. Each row follows by the indicated one or two tree rotations in each bottom-up step. All rows end with as the right child of , with both its subtrees empty. If instead two keys below are available, reflect the construction, exchanging left and right and reversing the order of keys. This proves splaying a chosen node into a leaf for every node of every splay tree of size at least four.
For a finite undirected graph , a vertex cover is a subset meeting every edge: for every , at least one of belongs to . The optimization problem asks for a vertex cover of minimum cardinality. Its usual decision version also supplies an integer and asks whether one exists with .
Construct a set cover problem instance whose universe is the set of edges . For each vertex , supply the set of all edges incident to . A collection covers the universe if and only if every edge has an endpoint in , which is precisely the vertex cover condition.
The correspondence preserves cardinality: a vertex cover of size is a feasible solution of the set cover problem using of these sets, and conversely. If two labelled vertices produce identical sets, one can keep their labels or discard duplicate choices without changing the optimum. The construction has size when incidences are listed, so it is a polynomial-time reduction.
Root the tree arbitrarily. For each vertex , let be the minimum vertex cover size in its descendant subtree, conditional on selecting , and the corresponding minimum conditional on omitting . Process the vertices in postorder traversal. For every child of ,At a leaf of a rooted tree, the empty sums give . Return at the root .
For algorithm correctness, if is selected, each child subtree may independently use its cheaper state, since the connecting edge is already covered by . If is omitted, each child must be selected to cover its connecting edge. Distinct child subtrees have no edges between them because the input is a tree. These observations prove the recurrences by structural induction. Each edge contributes constant work once, giving time complexity and space with adjacency lists. The single-vertex tree correctly has optimum zero. This is minimum vertex cover of a tree by dynamic programming.
In depth-first search of an undirected graph, every edge joins a vertex to one of its ancestors or descendants in the discovery tree. To see this directly, suppose is discovered before its neighbour . If is still undiscovered, the search from cannot finish before discovering : it eventually scans . Thus is discovered while the call for remains active and belongs to its descendant subtree.[ref]
Depth-first search by Jeff Erickson. Chapter 6, §6.1: active recursion intervals, tree/back edges and ancestor relations
For any edge , its ancestor endpoint therefore has a proper descendant and hence at least one child. It is an internal vertex of a rooted tree. Every edge has an internal endpoint, so the internal vertices form a vertex cover. The relevant leaves of a rooted tree here have no children in the rooted discovery tree; a root of vertex degree one can still be internal.
We construct an injection from the unmatched vertices in a matching to the leaves of a rooted tree. Start a downward graph path at each unmatched vertex . If the current vertex is a leaf of a rooted tree, stop. Otherwise choose any child . The current vertex is either the unmatched starting point or a vertex already matched to its own parent.
In either case, cannot be unmatched: the proper matching in a rooted tree condition would require its parent to be matched to one of 's siblings in a rooted tree, whereas that parent is either unmatched or already matched upward. Nor can be matched to its parent. Its matching partner must therefore be one of its own children, say . Extend the graph path by the two edges to and then to , and continue from .
Every extension descends two levels, so finiteness guarantees termination at a leaf of a rooted tree. Every visited vertex except the starting point is matched. The constructed graph paths for different unmatched starting points are disjoint: if two downward graph paths in a tree meet, one starting point must lie on the other path, which would put a second unmatched vertex after the first. That is impossible. Hence their terminal leaves of a rooted tree are distinct, provingOnly the properness condition for unmatched non-root vertices was used. If the root is unmatched and the convention exempts it because it has no parent, the same construction starts there and still works. Thus the root convention does not affect the claimed inequality. This proves the unmatched-vertex bound for a proper tree matching without requiring to have maximum size.
For a connected graph with at least one edge, run depth-first search and output the set of internal vertices of a rooted tree in its discovery tree . Part (d) proves that is a vertex cover. It is also connected: every ancestor of an internal vertex is internal, so the graph path in from that vertex to the root stays inside . The root is internal when .
For the approximation guarantee, choose a maximum-size proper matching in a rooted tree of , whose existence is supplied. It is used only in the analysis; the algorithm need not construct it. Since every matched edge uses two distinct vertices,By part (e), . ThereforeThe final inequality holds because every vertex cover of , connected or otherwise, must use at least one distinct endpoint for each of the disjoint edges in . Thus this is a 2-approximation algorithm in time complexity.
For completeness, a disconnected input needs a feasibility check: if two different connected components of a graph contain edges, no connected vertex cover can meet both. If exactly one component contains edges, run the construction on that component and ignore isolated vertices. If there are no edges, the empty vertex cover is optimal when an empty solution is permitted; if a nonempty connected solution is required, any single vertex is optimal for a nonempty input. These conventions cover the boundary cases omitted from the main approximation argument.
Use the standard maximum form of a linear programAn arbitrary linear program can be converted by the following operations.
- Replace minimization of by maximization of , and negate the resulting optimal value when translating back. A constant term in the objective is recorded separately.
- Replace every unrestricted variable by with both new variables nonnegative. A nonpositive variable can instead be negated. A lower bound can be eliminated by writing , ; other bounds remain linear inequalities.
- Multiply a row by . Replace an equality by the pair and .
These substitutions preserve the attainable objective values, up to the stated sign and constant corrections, and map feasible points in both directions. An alternative standard-form convention uses : add a nonnegative slack variable to each upper-bound row, or subtract a nonnegative surplus variable from a lower-bound row. The inequality convention above is used in the remaining solutions.
Let be the set of isolated vertices of the finite simple graph . Introduce a nonnegative integer for every vertex. Use the integer programEvery nonisolated vertex belongs to an edge, whose inequality and the other endpoint's nonnegativity already imply . The explicit bounds on therefore make all variables binary. For an integer feasible point, is an independent set, and its cardinality is the objective. Conversely the indicator vector of any independent set is feasible. Thus the optimal value is the maximum independent set size. Including the isolated-vertex bounds is essential for an arbitrary graph; without them the formulation would be unbounded whenever an isolated vertex is present.
Remove the integer requirements from the previous formulation to obtain its linear programming relaxation. Give each edge constraint a nonnegative dual variable , and each bound for a nonnegative dual variable . Since all right-hand sides are one, the dual linear program isAn integer feasible point selects a multiset of edges touching every nonisolated vertex, together with at least one singleton for each isolated vertex. Repeated edges or singleton choices can be discarded without losing coverage, so an optimum has a genuine edge cover of the nonisolated part and one singleton per isolated vertex. If has no isolated vertices, this is exactly an edge cover, with the objective counting selected edges including any unnecessary multiplicities. The isolated-singleton extension is necessary because a graph with an isolated vertex admits no ordinary edge cover.
This interpretation concerns integer feasible dual solutions. The linear programming relaxation can have fractional optima, so its value need not equal the integer independent set optimum. For example, the triangle has relaxed independent-set value , whereas its maximum independent set has size and its minimum edge cover has size .
Regard the two kinds of agents as the two sides of a complete bipartite graph, with edge weight . Pairing everyone is a perfect matching, and its maximum total weight is . Consider the capacitated linear programIt is feasible and bounded. Every optimum has all row and column sums equal to one: otherwise the equal total deficits of the two sides give a row and column both below one. Increasing by the smaller of their positive deficits remains feasible and increases the objective because , a contradiction.
Thus an optimum is a doubly stochastic matrix. By the Birkhoff-von Neumann theorem it is a convex combination of permutation matrices, so at least one corresponding perfect matching has weight at least its objective. Conversely every such perfect matching gives a feasible matrix. Hence . One way to justify the decomposition is to apply Hall's marriage theorem to the positive-entry support, subtract the smallest entry on a supported perfect matching, and repeat after rescaling the nonzero remainder; each subtraction removes a positive entry, so the process terminates.
The dual linear program assigns nonnegative dual variables to the row and column capacity constraints:These are exactly the permitted payments and all the pairwise acceptance conditions, so its optimal value is . It is feasible, for example by taking and . Strong duality now gives . In particular, the nonnegative payment restriction has been retained throughout; using capacity inequalities rather than equality constraints avoids introducing unrestricted prices.
For a direct weak duality check, sum over any pairing . Its revenue never exceeds the company's total offered payment. The linear programming duality and integrality argument prove that this lower bound on payments is attained.
Combine all inequalities, including nonnegativity, into ; explicitly, the rows encode . Let be a vertex of a linear polyhedron, equivalently an extreme point of the feasible linear polyhedron, and let index the active constraints there.
Suppose the active row normals have rank smaller than . By the rank-nullity theorem there is a nonzero vector with for every . Every inactive row has positive slack variable value . Since there are only finitely many rows, choose so small thatThen both and are feasible points: the active constraints remain equalities and no inactive inequality is violated. They are distinct, and is their midpoint, contradicting the extreme point property.
Therefore the active row normals have rank , and at least linearly independent constraints are satisfied with equality. In particular at least constraints are tight, as claimed. Nonnegativity bounds must be counted: for example, at the origin these can supply all active rows. Degeneracy can make more than constraints tight, so the result does not assert exactly .
Articles by others on the same topic
There are currently no matching articles.
